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.
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:
This is the fix:
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!
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:
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!
History
- 13th September, 2010: Initial post