Click here to Skip to main content
15,881,803 members
Articles / All Topics

Creating an Xcode Project Template

Rate me:
Please Sign up or sign in to vote.
4.57/5 (6 votes)
13 Sep 2010CPOL2 min read 48.7K   8   2
How to create an Xcode project template

Introduction

This article shows how to create an Xcode template from a Project. I am using the NoXIB project from my last article: 'Hello World, Goodbye .XIB!' -- A .XIB'less Hello World Application.

Copy / Paste your project folder in with the other templates at:
/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/.

The first thing to do is make sure every file gets its location relative to the project. On my Xcode, it defaults to storing absolute location, which seems really dumb. You can actually select all of the files, then right click -> GetInfo and change them all in one go.

Image 1

Now, we have to replace every occurrence of 'NoXIB' with '___PROJECTNAME___' -- everywhere!

(If you want to launch terminal from Finder, Google "OpenTerminalHere").

PiBook:NoXIB pi$ pwd
/Developer/Platforms/iPhoneOS.platform/Developer/
Library/Xcode/Project Templates/Application/NoXIB

PiBook:NoXIB pi$ chmod -R a+w *

PiBook:NoXIB pi$ find . -type f -print0 | 
xargs -0 perl -pi -e 's/NoXIB/___PROJECTNAME___/g'

The second line makes all files writable, so that the replace will work on. And no, I'm not a Linux Guru -- the guys on IRC.freenode.net#bash just pointed me to http://mywiki.wooledge.org/BashFAQ/021.

Need to do this for file names as well -- I just did it manually in Finder, as the bash script was a bit of a headache. It's only six files or something.

Check with terminal that you got everything -- my Finder window for some reason was not showing the .pch, so I had to rename it manually...

PiBook:NoXIB pi$ ls -la
total 48
drwxr-xr-x  10 pi    admin   340 27 Aug 16:19 .
drwxrwxr-x  11 root  admin   374 27 Aug 15:48 ..
-rw-r--r--   1 pi    admin  6148 27 Aug 16:20 .DS_Store
drwxrwxrwx  10 pi    admin   340 27 Aug 15:51 Classes
-rw-rw-rw-   1 pi    admin   203 27 Aug 15:50 NoXIB_Prefix.pch
-rw-rw-rw-   1 pi    admin   900 27 Aug 15:50 ___PROJECTNAME___-Info.plist
drwxrwxrwx   5 pi    admin   170 27 Aug 16:20 ___PROJECTNAME___.xcodeproj
drwxr-xr-x   3 pi    admin   102 27 Aug 16:19 build
-rw-rw-rw-   1 pi    admin   335 27 Aug 15:50 main.m

PiBook:NoXIB pi$ mv NoXIB_Prefix.pch ___PROJECTNAME____Prefix.pch

Yes -- that is four underscores as it had one already.

Now double click on ___PROJECTNAME___.xcodeproj to load it up in Xcode and check it builds & runs.

One warning:

BuildWarning.png

This is the fix:

Image 3

You just have to uncheck the box to stop the info.plist from going into the target. I don't know why this error comes up. Anyway, this fixes it!

Ok, now that it builds and runs, delete the /build folder and let's give it a whirl. Open Xcode -> new project, and there we go! There is our template! Try it out -- create a project!

Image 4

Ok, now to make it look nice! You've probably noticed that our template doesn't have an icon or a description. I'm going to try and see where the standard templates keep this information:

Image 5

Image 6

TemplateInfo.plist can just be copied over and edited.

A dab of Google uncovers http://www.devdaily.com/apple/mac-osx-create-icns-file-icon-png-free.

FastIcns is a cute piece of freeware that lets you create an .icns file out of a .png (IIRC I unchecked the 64x64 box as the OpenGL .icns didn't have that size)

Et... voila!

Image 7

History

  • 13th September, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United Kingdom United Kingdom
I like to create and invent things. Recent projects include: A novel computer interface (Google for JediPad), a new musical system (www.toneme.org), a speech typer (http://spascii.wikispaces.com/)

Currently I am making some innovative musical instruments for iPhone/iPad

PS Currently stranded in Thailand with no money! Great! So, if you like my articles, please consider putting some coins in the box. If I have to sell my MacBook and teach in a school, that means No More Articles! PayPal is sunfish7&gmail!com. Steve Jobbs -- if you're reading this, pay me to fix your documentation.

Comments and Discussions

 
Generalcorrection for template location Pin
Ohmu27-Sep-10 20:33
Ohmu27-Sep-10 20:33 
GeneralVery helpful Pin
Pavel Gnatyuk21-Sep-10 19:06
Pavel Gnatyuk21-Sep-10 19:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.