ios - Xcode 4 模板,创建空组

标签 ios xcode templates xcode-template

我正在尝试创建一个 xcode 4 模板。除了无法创建空组之外,一切正常。

我想要这样的项目结构: 项目名称 -楷模 - Controller -意见 -服务

<key>Definitions</key>
<dict>

    <key>Views/RootViewController.h</key>
    <dict>
        <key>Group</key>
        <string>Controllers</string>
        <key>Path</key>
        <string>RootViewController.h</string>
        <key>TargetIndices</key>
        <array/>
    </dict>

    <key>Views/RootViewController.m</key>
    <dict>
        <key>Group</key>
        <string>Controllers</string>
        <key>Path</key>
        <string>RootViewController.m</string>
    </dict>

    <key>en.lproj/RootViewController.xib</key>
    <dict>
        <key>Group</key>
        <string>Views</string>
        <key>Path</key>
        <string>RootViewController.xib</string>
    </dict>

    <key>en.lproj/MainWindow.xib</key>
    <dict>
        <key>Group</key>
        <string>Views</string>
        <key>Path</key>
        <string>MainWindow.xib</string>
    </dict>

    <key>Services</key>
    <dict>
        <key>Group</key>
        <string>Services</string>
        <key>Path</key>
        <string>Services</string>
        <key>TargetIndices</key>
        <array/>
    </dict>
</dict>

<key>Nodes</key>
<array>
    <string>en.lproj/MainWindow.xib</string>
    <string>Views/RootViewController.h</string>
    <string>Views/RootViewController.m</string>
    <string>en.lproj/RootViewController.xib</string>
    <string>Services</string>
</array>

Views 组被创建,因为文件被添加到这个文件夹。

服务组也已创建,但其中有一个名为“服务”的文件(没有扩展名)。

最佳答案

我想我来晚了一点,但我自己测试得到了答案。 你几乎是正确的,你只需要删除文件夹的组 key 。 XCode 将自行创建组。例如,只有服务的代码是这样的:

<key>Definitions</key>
<dict>
    <key>Services</key>
    <dict>
        <key>Path</key>
        <string>Services</string>
    </dict>
</dict>

<key>Nodes</key>
<array>
    <string>Services</string>
</array>

就是这样,我希望它能帮助你或其他人。

以防万一有人想尝试创建示例项目然后重命名所有文件名和内容的其他选项,请在我使用的 bash 脚本下方找到附件:

#!/bin/bash -e

# Read the settings from the project
read -p "Project's name: " project_name
read -p "Class prefix: " class_prefix

# Set variables
date="$(date +%d-%m-%Y)"
year="$(date +%Y)"
username="PLACE_YOUR_NAME_HERE"
organization="PLACE_YOUR_ORGANIZATION_NAME_HERE"

# Copy the base project template to a new folder with the projects name
cp -r ___PACKAGENAME___/ $project_name

# Rename files and folders to match the project name
cd $project_name

# Match the project name
for file in $(find . -depth -name '*___PACKAGENAME___*')
do
    dir="$(dirname "$file")"
    old="$(basename "$file")"
    new="$(echo "$old" | sed s/___PACKAGENAME___/"$project_name"/)"

    if [ "$new" != "$old" ]; then
        mv "$dir"/"$old" "$dir"/"$new"
    fi
done

# Add the class prefix
for file in $(find . -depth -name '*___VARIABLE_classPrefix___*')
do
    dir="$(dirname "$file")"
    old="$(basename "$file")"
    new="$(echo "$old" | sed s/___VARIABLE_classPrefix___/"$class_prefix"/)"

    if [ "$new" != "$old" ]; then
        mv "$dir"/"$old" "$dir"/"$new"
    fi
done

# Modify the content of the files
for file in $(find . -depth -type f ! -name .DS_Store ! -path "*Externals/*" ! -name "*.png" ! -name "*.xcuserstate" )
do
    filename="$(basename "$file")"
    if [ "$filename" != '*.DS_Store*' ]; then
        echo $filename
        sed -e "s/___PROJECTNAME___/${project_name}/g" $file > temp
        sed -e "s/___FULLUSERNAME___/${username}/g" temp > $file
        sed -e "s/___DATE___/${date}/g" $file > temp
        sed -e "s/___ORGANIZATIONNAME___/${organization}/g" temp > $file
        sed -e "s/___YEAR___/${year}/g" $file > temp
        sed -e "s/___PACKAGENAME___/${project_name}/g" temp > $file
        sed -e "s/___VARIABLE_classPrefix___/${class_prefix}/g" $file > temp
        mv temp $file
    fi
done

在这种情况下,我首先创建了示例项目并将其命名为 ___PACKAGENAME___ 之后我只是更改了文件中的其他一些字段(例如日期)以便能够使用脚本更改它们.

此代码是在 2013 年 4 月创建的,所以距离我上次使用它已经有一段时间了,现在我没有太多时间来审查和检查是否一切正常。但是,如果其他人对这项工作的原理感兴趣,我想我将能够找到将所有内容上传到 Github 的空白。

关于ios - Xcode 4 模板,创建空组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6535328/

相关文章:

swift - 使 Collection View 左右滚动

ios - 使用 statusBarOrientation 的 iPad 设备方向

c++ - 在 C++ 中绑定(bind) lambda

python - Sphinx 自动图像编号/标题?

ios - 如何通过键值从 firebase 中检索对象

ios - AirWatch身份验证失败

ios - 将 setTitle 更改为 setImage

c++ - 如何访问模板模板类的 typedef

ios - 当我导航到包含 ARSCNView 的 View Controller 时,会出现空白屏幕

ios - 从 FilePath 的 NSArray 获取图像?