Xcode 4 template, create empty group
Asked Answered
B

1

4

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

Barrada answered 30/6, 2011 at 13:15 Comment(0)
M
1

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.

Miff answered 17/4, 2013 at 15:45 Comment(6)
Could you be more explicit? What are you trying to create, source files, etc.Miff
In this case, just creating an empty group. Are we supposed to mirror the xml with the same file structure in the template folder?Utilitarianism
I have been doing some testing and it seems that this way stopped working in XCode 5, I'm getting an empty file too. But besides that, you can always create a group containing a file like is explained here: https://mcmap.net/q/408875/-creating-sub-groups-in-xcode-4-templates I've seen you commented there too, but it really works (just tested). In the end, because of some other limitations, I stop using templates, I created a sample project the way I wanted to be, I copy it and then I pass some scripts to change the name of the variables like project names and folders.Miff
I will give it a second-over, thanks for your thoughts.Utilitarianism
@Miff Can you share any of your script? I have no idea how to write the script which changes project name, that would really be helpful as templates work awfully.Lailaibach
@Vive I've just updated my comment with the script I was using. I hope you will find it usefulMiff

© 2022 - 2024 — McMap. All rights reserved.