7

While there is quite a lot of documentation and example for creating templates in XCode 3 converting them to XCode4 Templates is quite a nightmare...

First here is what i've found:

  • BorealKiss provides a nice tutorial for staters
  • Cocos2d has some very nice examples to make your templates more "evolved"

But all of them fail to answer this sample question:

How can someone create Folders Insider other Folders ?

For example if you want to have files inside a group you should write:

<key>Definitions</key>
<dict>
    <key>File1.h</key>
    <dict>
        <key>Group</key>
        <string>Group1</string>
        <key>Path</key>
        <string>File1.h</string>
        <key>TargetIndices</key>
        <array/>
    </dict>
    <key>File1.m</key>
    <dict>
        <key>Group</key>
        <string>Group1</string>
        <key>Path</key>
        <string>File1.m</string>
    </dict>
</dict>

<key>Nodes</key>
<array>
    <string>File1.h</string>
    <string>File1.m</string>
</array>

but how would you go for having Group1 inside Group2 for example.

I've tried many many things, playing with ancestors and all but nothing worked. Any piece of advice or any documentation (I couldn't find any on those XCode templates) would be greatly appreciated.

Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
apouche
  • 9,703
  • 6
  • 40
  • 45

3 Answers3

20

I've tried many times modify the TemplateInfo.plist and I've also tried to make a sub group and put files in them. Finally I found the solution:

Definition section:

<key>Definitions</key>
<dict>
    <key>main.h</key>
    <dict>
        <key>Path</key>
        <string>main.h</string>
        <key>Group</key>
        <array>
            <string>parent</string>
            <string>child</string>
        </array>
    </dict>
</dict>

in the node section:

<key>Nodes</key>
<array>
    <string>main.h</string>
</array>

The code above will create groups parent and child. and the main.h is in the child

Project
--parent
---child
----main.h
codecarver
  • 249
  • 2
  • 10
  • litte-buddy Thank You !! You're answer was clear and solved many hours of searching and tweaking ! I took the liberty to slightly edit your answer to show how to make it work for multiple parents – apouche Apr 08 '11 at 19:06
  • u're welcome apouche. have u success to include folder reference from project template?? please take a look my question about this [link](http://stackoverflow.com/questions/5575294/how-to-add-folder-reference-in-xcode-4-project-template) – codecarver Apr 11 '11 at 06:22
  • Is there more I have to do to create a group? Using your example as it is, I fail to create a group for main.h – Morkrom Dec 16 '13 at 22:51
  • @little-buddy, Can you please explain where exactly does the Definitions and Nodes should be in the xml file in order for them to work ? I have an XML with Options that holds the files, so where exactly should they be ? Thanks. – OhadM Jan 05 '17 at 20:28
  • 4
    I understand that's for a project template, any idea if it's possible to do the same for a file template `TextSubstitutionFileTemplateKind`? – Pablo A. Jan 25 '17 at 12:50
1

I've been struggling with this one myself too. As a workaround I've created and added a folder in my TemplateInfo.plist location (in your case that should be folder named Group1). The folder layout (subfolders and files) are the same as I want them to be in my project source tree ( e.g folder 'Group1' has subfolder 'Group2', folder 'Group2' has files File1.h and File1.m etc). Then I just add the root folder (Group1) in my TemplateInfo.plist file by defining it in the Definition section and by adding it to the Nodes section like this:

<key>Definitions</key>
<dict>
<key>Group1/</key>
<dict>
<key>Path</key>
<string>Group1/</string>
<key>TargetIndices</key>
<array/>
</dict>

<key>Nodes</key>
<array>
<string>Group1</string>
</array>
denicija
  • 186
  • 2
  • 5
  • This is an interesting solution but it doesn't seem to work or maybe I not doing it correctly. How do you define the files inside Group1 then ? Because it leaves me we a strange behavior where every subfolder is replicated recursiverly Group1=>(Group2=>(Group1=>Group2)) Type of things – apouche Apr 01 '11 at 19:50
  • Well there is no need of defining the files in Group2 since they are complete xcode files. Instead of defining them in the TemplateInfo.plist I simply create new XCode files (like when creating a file in some project) and I write the headers, methods etc in the file itself. Then I copy them to the Group2 subfolder in my template location. I think the other problem you have is because you probably define and then add Group2 in the nodes section of the template also. Once you've done that for Group1, there is no need to make the same for it's sub-contents since they will be automatically added – denicija Apr 02 '11 at 18:06
  • denicija thanks a lot but it didn't work with my version of XCode 4 (Build 4A304a). When i added a group the way you mentioned I added up having a strange behavior (folders were adding themselves recursively) – apouche Apr 08 '11 at 19:08
1

enter image description here

For anyone that needs help, this is on Xcode 12.4, this is a project template.

                        <key>Nodes</key>
                    <array>
                        <string>ViewController.swift:comments</string>
                        <string>ViewController.swift:imports:importCocoa</string>
                        <string>ViewController.swift:implementation(___FILEBASENAME___: UIViewController)</string>
                        <string>ViewController.swift:implementation:methods:viewDidLoad(override func viewDidLoad(\))</string>
                        <string>ViewController.swift:implementation:methods:viewDidLoad:super</string>
                        <string>Info.plist:UIMainStoryboardFile</string>
                        <string>Info.plist:UIApplicationSceneManifest:UISceneStoryboardFile</string>
                        <string>Base.lproj/Main.storyboard</string>
                        <string>Some/MainCoordinator.swift</string>
                        <string>Some/Other/TestClass.swift</string>
                    </array>
                    <key>Definitions</key>
                    <dict>
                        <key>Base.lproj/Main.storyboard</key>
                        <dict>
                            <key>Path</key>
                            <string>Main.storyboard</string>
                            <key>SortOrder</key>
                            <integer>98</integer>
                        </dict>
                        <key>Info.plist:UIMainStoryboardFile</key>
                        <string>&lt;key&gt;UIMainStoryboardFile&lt;/key&gt;
                            &lt;string&gt;Main&lt;/string&gt;
                        </string>
                        <key>Some/MainCoordinator.swift</key>
                        <dict>
                            <key>Group</key>
                            <array>
                                <string>Some</string>
                            </array>
                            <key>Path</key>
                            <string>MainCoordinator.swift</string>
                        </dict>
                        <key>Some/Other/TestClass.swift</key>
                        <dict>
                            <key>Group</key>
                            <array>
                                <string>Some</string>
                                <string>Other</string>
                            </array>
                            <key>Path</key>
                            <string>TestClass.swift</string>
                        </dict>
                    </dict>
Alejandro Vargas
  • 1,327
  • 12
  • 26