Reputation: 3165
I'm trying to add a custom code template into Xcode. Based on my reading, this is the procedure I've come up with.
First, access the folder path
Application/Xcode45-DP3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application
Second, make a copy of one of the existing folders to use as a starting point.
Third, change that folder name to what I want.
The part that I'm having trouble with is that there are no files with the code that I want to modify, such as PROJECTNAME.xcodeproj, anyfilename.h, anyfilename.h, etc., there is only MainStoryBoard_iPad(and iPhone).storyboard, ViewcontrolleriPad(and iPhone).Xib, TemplateIcon.tiff and TemplateInfo.plist.
What's the proper way to do this? What am I missing?
Upvotes: 2
Views: 1286
Reputation: 32681
What are you trying to create? A project Template or a File Template?
"*.xctemplate"
folder from "/Xcode/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates"
(that you will use as an example/starting point) to "~/Library/Application Support/Developer/Shared/Xcode/File Templates"
."*.xctemplate"
folder from "/Xcode/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates"
to "~/Library/Application Support/Developer/Shared/Xcode/Project Templates"
"File Templates"
/"Project Templates"
folder is not present in App Support, create them.Don't copy the template into the Xcode bundle itself as it is not intended to (and violates the sandbox concept, and will be overridden the next time you upgrade your Xcode version) but use the Application Support
folder for that as it is its very purpose.
Once you have copied one .xctemplate
folder from the Xcode bundle to the corresponding App Support folder, you can modify the content of the .xctemplate
to fit your needs.
Now for the fact that you don't have any xcodeproj in the xctemplate folder, this is because the project that is created by a Project Template is not defined using a xcodeproj file, but rather with keys in the TemplateInfo.plist file.
For example, in "Project Templates/Mac/Mac Base.xctemplate/TemplateInfo.plist"
you can see a key named "Project"
with subkeys "Configurations"
, "SDK"
, and "SharedSettings"
that defines some Build Settings for the xcodeproj to be created by the template.
Moreover, be aware that templates have some kind of "inheritance" concept, each template being able to have "ancestors" that define common keys:
"TemplateInfo.plist"
file and look at the "ancestors"
key"Cocoa Application.xctemplate"
template have "com.apple.dt.unit.cocoaApplicationBase"
as one of its ancestor."Cocoa Application Base.xctemplate"
template, as in its TemplateInfo.plist
you can see that its "Identifier"
key is the "com.apple.dt.unit.cocoaApplicationBase"
we saw above).And You can go up like that until the base template, having some kind of "inheritence" for the template definition.
Upvotes: 4