Xcode 4模板,创建空组

发布于 2024-11-17 16:18:30 字数 2041 浏览 6 评论 0原文

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

我想要这个项目结构: 项目名称 -模型 -控制器 - 景观 -Services

<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 组被创建,因为文件被添加到此文件夹中。

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

I'm trying to create a xcode 4 template. Everything works fine except for the fact that I can't create an empty group.

I would like to have this project structure:
ProjectName
-Models
-Controllers
-Views
-Services

<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>

The Views group gets created, because files get added to this folder.

The Services group also gets created but there is a file called 'Services' in it (without an extension).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二手情话 2024-11-24 16:18:30

我想我来得有点晚了,但我刚刚得到了自己测试的答案。
您几乎是正确的,您只需要删除文件夹的组密钥即可。 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。

I suppose I arrive a little bit late but I just got the answer testing it on my own.
You have it almost correct, you only need to delete the group key for the folders. XCode will create the groups on its own. For example the code for only Services will be like this:

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

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

That's it, I hope it will help you or anybody else.

Just in case anybody wants to try the other option creating a sample project and then renaming all the file names and content, find attached below the bash script I was using:

#!/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

In this case, I created first the sample project and I call it ___PACKAGENAME___ after that I just changed some other fields inside the files like the date in order to be able to change them with the script.

This code was created at April 2013 so it's been a while since the last time I used it and right now I don't have so much time to review and check if everything is ok. But if anybody else is interested in how this work I guess I will be able to find a gap to upload everything to Github.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文