How to add new templates in Xcode for iPhone application developement?
问题:
回答1:
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
.
回答2:
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:
- File templates: ~/Library/Developer/Shared/Xcode/File Templates/
- Target templates: ~/Library/Developer/Shared/Xcode/Target Templates/
- Project templates: ~/Library/Developer/Shared/Xcode/Project Templates/
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].
回答3:
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.
回答4:
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.
回答5:
I wrote an article on how to create a new Xcode template from an existing project here.
It covers:
- specifying your project files are relative to the project path
- using the commandline to search / replace & fiddle file permissions
- excluding info.plist from the target membership
- giving your template an icon
It doesn't cover where to put the template. That information is covered in other answers.
回答6:
You can use this template which is a well researched one available in the market.
http://www.binpress.com/app/ios-boilerplate-and-template/1597
回答7:
I had taken reference from this link, its really helpful having some correction in benny answer which I mentioned in comment
How to create project templates in Xcode 4