【问题标题】:Xcode 4 template, create empty groupXcode 4模板,创建空组
【发布时间】:2011-09-25 23:49:41
【问题描述】:

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

我想要这个项目结构: 项目名 -楷模 -控制器 - 意见 -服务

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

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

【问题讨论】:

    标签: ios xcode templates xcode-template


    【解决方案1】:

    我想我到的有点晚,但我自己测试了一下才得到答案。 你几乎是正确的,你只需要删除文件夹的组键。 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。

    【讨论】:

    • 你能说得更清楚些吗?您要创建什么,源文件等。
    • 在这种情况下,只是创建一个空组。我们是否应该在模板文件夹中镜像具有相同文件结构的xml?
    • 我一直在做一些测试,似乎这种方式在 XCode 5 中停止工作,我也得到一个空文件。但除此之外,您始终可以创建一个包含文件的组,如下所述:stackoverflow.com/a/5561131/1387646 我也看到您在那里发表了评论,但它确实有效(刚刚测试过)。最后,由于其他一些限制,我停止使用模板,我按照我想要的方式创建了一个示例项目,我复制了它,然后我传递了一些脚本来更改项目名称和文件夹等变量的名称。
    • 我会再做一遍,谢谢你的想法。
    • @Vive 我刚刚用我正在使用的脚本更新了我的评论。我希望你会发现它有用
    猜你喜欢
    • 1970-01-01
    • 2016-04-26
    • 2013-03-07
    • 2023-03-18
    • 2017-05-19
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多