How to add new templates in Xcode for iPhone application developement?
From my answer to this question:
XCode uses template files for file and project templates and does variable expansion in both at creation time.
XCode 3.0-3.1 templates can be found in [Dev Installation]/Library/Xcode/, likely /Developer/Library/XCode. If you want to modify these templates or add your own, use the following directories to save your new/modified templates so that they are not wiped out by future Developer Tool upgrades:
I think that you can also use the /Library/Developer/Shared/Xcode/[File|Target|Project] Templates/ directory for templates shared by all users.
A good tutorial on writing file templates is here [MacResearch.org].
You can make a template through changing the contents of the developer folder. I have done this myself. Let's say, you were making an html template: Step 1. Go to:/Developer/Library/Xcode/Templates/file templates/resource Step 2. make a folder there called HTML File.xctemplate. Step 3. Copy the contents of the RTF file folder Step 4. Paste the contents in your html folder. Step 5. Change the rtf extention of the
___FILEBASENAME___.rtf(in your html folder) to .html
Step 6. Change the plist file to:
Key | Type | Value
DefaultCompletionName String File
Description String An empty Hyper Text Markup language (HTML) file.
Kind String Xcode.IDEKit.TextSubstitutionFileTemplateKind
MainTemplateFile String ___FILEBASENAME___.html
Name String Hyper Text Markup Language file
Summary String An empty Hyper Text Markup Language (HTML) file
Step 7. now, when you add a new file, if you go to resources, you will find an html template. PS You just need to replace the html text to your choice, such as ruby.
XCode 4 changes how templates work, and where templates go, so be careful following instructions unless they refer to XCode 4. You can find a few template examples, and the paths to where they go in my XCode4 customization repository:
https://github.com/KiGi/XCode4Customization
The paths where the system templates live is:
/Developer/Platforms/iPhoneOS.platform/Developer/Library/ Xcode/Templates/File Templates
Don't change those, copy and modify in your own library directory:
~/Library/Developer/Xcode/UserData/File Templates
Those paths are also in the "WhereToPlaceFiles" RTF file on github.
For some advices, I suggest to take a look at answers to a related question: Change templates in Xcode.
In particular, if you want your modifications not to be lost whenever you upgrade Xcode, put your templates in ~/Library/Developer/Shared/Xcode
, not under /Developer
.
I wrote an article on how to create a new Xcode template from an existing project here.
It covers:
It doesn't cover where to put the template. That information is covered in other answers.