Documentation: Xcode 4 Templates

What you’ll get in bulletpoints:

  • Five tutorials on how to create File and Project templates
  • Extensive reference for all known TemplateInfo.plist items (keys) and settings
  • Explanation of the placeholders (eg ___FILENAME___) and variables (eg ___*___)
  • Frequently Asked Questions answered
  • Many tips and tricks
  • Total of 70 pages of documentation (PDF) from 70+ hours of experimentation
  • File and Project Template example files

Buy Now For USD $10 / EUR €7,50

Synopsis

This unofficial but comprehensive Xcode 4 Template documentation explains how to create File and Project Templates for Xcode 4. Xcode 4 uses a template format significantly different from the one used in Xcode 3, which renders all previous information on Template creation useless. The new format is also much more complex and allows for greater flexibility, for example a template can now consist of multiple inherited templates.

This Xcode 4 Template documentation first gives you a quick overview what File and Project templates are. Step-by-step tutorials show you how to create your own File and Project Templates. In the reference section the format of the TemplateInfo.plist and related files are meticulously documented. Finally there’s the Frequently Asked Questions (FAQ) section with answers to common questions. The documentation is fully hyperlinked so that you can quickly look up keywords in the reference section. Several example files for File and Project Templates help you get started and can be used as the basis for your own templates.

Disclaimers

This is not official documentation. I can not guarantee that the documentation is 100% correct, much of the information was found out through lots of trial and error. Nevertheless this documentation contains a lot more information than what is currently available on the Internet.

THE DOCUMENTATION IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DOCUMENTATION OR THE USE OR OTHER DEALINGS IN THE DOCUMENTATION.

License

Quality documentation takes a lot of time and effort to produce. This document is only available for a nominal fee.

Provided that you paid the nominal fee, you (as an individual) are entitled to read this document as many times as you want. You may also print it as many times as you want. You can even delete the electronic file from your computer or burn the printed pages.

You may not: distribute, forward, share, publish, host, upload, quote or otherwise make publicly available this document or copies of it in any form (printed or electronic) without prior written permission by Steffen Itterheim. You may not rent, lease, sublicense or otherwise transfer your usage rights of this document to another individual, institution or company.

The information you learned from reading this documentation is free. It means you can use everything in this documentation and whatever you learn from reading this documentation in any way you want, as long as you depict it in your own words and images. Exempt from that are technical keywords and identifiers which must be depicted unchanged in order to convey their meaning.

You may use the example template files in any way you want.

This document does not use any form of DRM or copy protection. It means I trust you not to share it illegally. Please do not violate that trust, thank you!

Buy Now For USD $10 / EUR €7,50

26 Responses to “Documentation: Xcode 4 Templates”

  1. mana says:

    Hi, i’m interessed in the book, but i have a question: mi problem is how to create a template to generate a project with links to mi already existent static libraries. Does it include any sample about it? Thanks.

  2. Hi,
    I would love to start to program with Xcode 4, but I am a real noob at it. No experiences at all except on database like 4dimension :)

    I just would like to know that if your template/book, would help a newbie or should I try to find first a “Book for the dumb” ? (in french we do have a book’s collection called “pourlesnuls” (forthedumbs) to help for the really first step… :)

    Best Regards,
    Charles

    • In english there’s a book series “for Dummies” which is quite popular and yes, there’s a Objective-C for Dummies.
      Personally, I learned Objective-C from Learn Objective-C on the Mac from Apress.

      You don’t need to know much of Xcode to start working with it, respectively what you need to know you can research via google whenever you need some help. I think the crucial parts are usually explained in good Objective-C books.

      You can also preview my Learn Cocos2D book on google to see if it matches with your level of experience.

  3. Karl Jones says:

    BRILLIANT, with this resource in front of me creating file projects seemed really simple.Thanks!
    karl

  4. Peter says:

    Does this include the features or capabilities described in your “My professional cocos2d Xcode Project Template”? (http://www.indiepinion.com/steffenj/my-professional-cocos2d-xcode-project-template/)

    • I’m not sure what exactly you’re referring to but I would say no. Basically because this doc is for the new Xcode 4 template format, the tutorial describes how to setup cocos2d as external reference in an Xcode 3 project. Unfortunately, adding external .xcodeproj files is one of the few things the Xcode 4 Template format does not support in a satisfactory way (there are manual steps required to make externally references projects work in Xcode 4 project templates).

      • Peter says:

        The earlier “professional cocos2d Xcode Project Template” appears to focus on results, leveraging Xcode 3 capabilities to get things done. That blog post includes a bulleted feature list for that template.

        The newer “Docs: Xcode 4 Templates” appears to be the “missing manual” detailing all Xcode 4 capabilities. But does it also provide a finished template with all or most of the capabilities of the earlier template? Or is creating an Xcode 4 template with those same capabilities left as an exercise for the reader?

        I’m ready to transition from “can I really do this” initial development, to “time to get serious about releasing a product” development. I’m hoping to adopt a suitable Xcode template to assist me in doing that.

        I should mention I bought your book, it’s been *tremendously* helpful, as have the many other resources you’ve provided. Thanks!

        • There are example templates in the Xcode 4 Template documentation (product on this page). However, they are not cocos2d project templates.

          Moreover, the older Xcode 3 Template Tutorial for Cocos2D is labelled a bit misleading as “template”, it’s not a template that you can create via File -> New Project in Xcode – it’s a project that I used as template for my own projects by copying the entire folder.

  5. Fabrice says:

    Hello Steffen, Thx a lot for this document

    I have just one question, i bought with paypal your doc but after the confirm how i download the doc ??? i don’t have seen any links and nothing in my email box just the paypal ticket maybe you will send me after verification ???

    have a good day

    (My english level is not perfect i hope you will understand me) bye

  6. Jim says:

    This is a great resource, but there’s one thing that I can’t seem to make work – groups.

    It seems that groups are created automatically when you include definitions for files and specify that they are in groups. That’s useful, but I want to be able to specify the path of a group.

    You can do this in Xcode and the result is that new files created within that group are automatically placed in the right subdirectory on disk. It’s great for keeping things organised.

    In other words, I want the on-disk layout to be Foo/Bar/Baz.txt, and I want matching groups:

    Foo should have a path of Foo, relative to its enclosing group.
    Bar should have a path of Bar, relative to its enclosing group, with its parent being Foo.
    Baz.txt should have a path of Baz.txt, relative to its enclosing group, with its parent being Bar.

    However because the groups are created automatically, there’s no opportunity to supply a Path entry. If I only define Baz.txt, then Foo and Bar are created, but their paths are blank.

    I tried to specify the groups manually by giving them definitions and nodes, but that has the result of trying to copy them as directories instead, meaning that the files and directories within are copied twice and all kinds of weirdness ensues.

    This is also a problem when trying to create empty groups.

    It’s not clear from your documentation whether this is possible or not. Have you solved this problem?

    • Groups in the Xcode 4 templates are sketchy at best. What you can do is use the “Group” in “Definitions” but change it from string to array. From the documentation (p35): “If Group is an array, you can specify subgroups by creating an array item for each group. For example, to put a file into the group path /Classes/MyCode/Tests/ you would add in the same order three array items: Classes, MyCode and Tests without the slashes.”

      What I believe you can’t do is to have files in one folder but in a differently named group or group path in Xcode.

      • Jim says:

        Yeah, I got that. Creating nested groups I can do no problem. It’s setting the path for the groups that’s the issue. I experimented with putting dictionaries into the array instead of strings, but didn’t find anything that wasn’t ignored. I checked the official templates, and none of the groups in them have paths set, so I reckon it’s an inherent limitation of the template system unfortunately.

    • Ralph says:

      It works with

      Assets

      Path
      Assets
      TargetIndices

      and an entry in the Nodes array

      Nodes


      Assets

  7. Neil says:

    Has anyone figured out how to add headers to the Copy Headers build phase in a template? This is the last piece of the puzzle for my own template.

  8. Ron says:

    Regarding the CopyFiles build phase:

    I have figured out that the DstSubfolderSpec is the 1-based index of the selected item in the Destination popup menu. The items in the menu for Xcode 4.0.1 are:

    1 Absolute Path
    2 Separator
    3 Product Directory
    4 Separator
    5 Wrapper
    6 Executable
    7 Resources
    8 Java Resources
    9 Frameworks
    10 Shared Frameworks
    11 Shared Support
    12 PlugIns

    If you open a project and manually create a CopyFiles phase, set the Destination to Resources and add file to be copied, close the project, then open the project.pbxproj file in a text editor, you’ll see a CopyFiles section that looks like:

    /* Begin PBXCopyFilesBuildPhase section */
    082486231469AFBE0019A165 /* CopyFiles */ = {
    isa = PBXCopyFilesBuildPhase;
    buildActionMask = 2147483647;
    dstSubfolderSpec = 7;
    files = (
    082486451469B1150019A165 /* my_file_to_copy.txt in CopyFiles */,
    );
    runOnlyForDeploymentPostprocessing = 0;
    };
    /* End PBXCopyFilesBuildPhase section */

    Note that dstSubfolderSpec == 7 and that there is a “files” array.

    In a project template, adding a CopyFiles build phase and setting DstSubfolderSpec to 7 gives the same result EXCEPT that there does not seem to be any way to specify the “files” array. I’ve tried every way I can think of (around 100 different combinations including using Definitions and Nodes, arrays named “files” and “Files”, etc.), but the files array in the resulting project is always empty.

    Note that Apple’s single example that uses a CopyFiles build phase (the Mac Command Line Tool template) has the same result: a PBXCopyFilesBuildPhase section is created but the files array is empty.

  9. Ruslan says:

    Hello Steffen. Could you please help me?

    1) Are there an information about adding more then one target to project in this documentation?
    2) Can I add some file only for one target (e.g. create two targets, one regular and second for unit tests, and add tests source only into second target for compilation)?

    Thanks in advance!

  10. karthik says:

    Hi Steffen

    I read your xcode 4 template documentation. It was worth the reading and was able to create my own templates. i had one question do we have to follow similar steps for creating templates for xcode 4.2.

  11. RF says:

    Hi Steffen,

    Great job with the doc. It’s really helped with getting over the main hump. But I’ve hit a couple of problems (this is under Xcode 4.2.1). Perhaps you can point me in the right direction:

    1. How do you add a dylib (like libxml2.2.7.3.dylib or libicucore.dylib)?

    The “Frameworks” section works fine for adding known frameworks, but these are dylibs in /usr/lib. Just adding them in manually doesn’t work because it assumes they’re resident in the current directory and the path is all wrong. Adding them into the Frameworks section automatically appends a .framework to the name.

    2. On a related note, how does one go about adding a custom framework, i.e. one made by a third-party installed in a non-shared directory, perhaps with the path defined in an environment variable?

    Maybe you’ve already described it in the Template Doc book and I’ve just missed it.

    Any tips (or pointers to examples) appreciated.

    • 1) I believe that’s not possible, at least I don’t know a way to do this.
      2) Same for custom frameworks or static libraries (.a).

      Because of these issues I ended up not using Xcode 4 project templates for Kobold2D, and instead devised my own mechanism and a tool to provide template projects. It has the positive side-effect that it makes creating additional template projects dead easy, it’s just a regular project with a specific name and folder location.

    • thrusty says:

      Regarding (1) this seems to work for me:

      libsqlite3.dylib

      PathType
      DeveloperDir
      Path
      /usr/lib/libsqlite3.dylib
      FileType
      wrapper.framework

Leave a Reply