We are trying to make a project template, but the documentation on this is spotty or non-existent.
Doing some reverse-engineering on some template files, we have come up with the following. However, it doen't actually work!
First of all, we have figured out that project templates should be installed inside:
~/Library/Application Support/Developer/Shared/Xcode/Project Templates
We have made project and installed it here, and this part works - we see this show up in the "User Templates" section of the Xcode "New Project" chooser.
The project folder contains the following files. As you can see, I want the file names to be subsituted (that part works) but as you will see, I also want the contents of the files to be substituted; this doesn't happen.
- ___PROJECTNAME___.xcodeproj
- ___PROJECTNAMEASIDENTIFIER____Prefix.pch
- ___PROJECTNAMEASIDENTIFIER___.icns
- ___PROJECTNAMEASIDENTIFIER___Delegate.h
- ___PROJECTNAMEASIDENTIFIER___Delegate.m
- ___PROJECTNAMEASIDENTIFIER___Template.html
- Debug.xcconfig
- en.lproj
- Info.plist
- Release.xcconfig
I have put in two special files into the ___PROJECTNAME___.xcodeproj package:
- TemplateInfo.plist
- TemplateIcon.icns - the icon to show up in the New Project window
If I create a new project (called "Foo & Bar" as a stress test) using this template, these are the files it creates:
- Debug.xcconfig
- en.lproj
- Foo & Bar.xcodeproj
- Foo___Bar_Prefix.pch
- Foo___Bar.icns
- Foo___BarDelegate.h
- Foo___BarDelegate.m
- Foo___BarTemplate.html
- Info.plist
- Release.xcconfig
So far so good!
But looking in the file contents, I get things like this. Here is the contents of Foo___BarDelegate.m:
//
// «PROJECTNAMEASIDENTIFIER»Delegate.m
// «PROJECTNAME»
//
// Created by «FULLUSERNAME» on «DATE».
// Copyright «ORGANIZATIONNAME» «YEAR» . All rights reserved.
//
#import "«PROJECTNAMEASIDENTIFIER»Delegate.h"
@implementation «PROJECTNAMEASIDENTIFIER»Delegate
@end
The apparent issue is that somehow I'm doing the TemplateInfo.plist wrong. But then again, notice how not only are my special items not being substitued, but the standard items don't even get replaced! So maybe it's a deeper issue.
But with a problematic TemplateInfo.plist being my best hypothesis, I present a couple of variations I have tried. Neither work.
Either:
{
FilesToMacroExpand = (
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_\_Prefix.pch",
"en.lproj/InfoPlist.strings",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_\_Prefix.pch",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_.icns",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_Delegate.h",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_Delegate.m",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_Template.html",
"Info.plist"
);
Description = "This project builds a cocoa-based \"element\" plugin for Sandvox.";
}
or:
{
FilesToMacroExpand = (
"«PROJECTNAMEASIDENTIFIER»\_Prefix.pch",
"en.lproj/InfoPlist.strings",
"«PROJECTNAMEASIDENTIFIER»\_Prefix.pch",
"«PROJECTNAMEASIDENTIFIER».icns",
"«PROJECTNAMEASIDENTIFIER»Delegate.h",
"«PROJECTNAMEASIDENTIFIER»Delegate.m",
"«PROJECTNAMEASIDENTIFIER»Template.html",
"Info.plist"
);
Description = "This project builds a cocoa-based \"element\" plugin for Sandvox.";
}
Update: I've also tried adding the "FilesToRename" key, even though the ___ seems to be automatically causing renaming to happen. This is the plist contents with that in, in XML format (since some people were worried about that UTF-8 nature of things -- yes, it's a valid plist):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Description</key>
<string>This project builds a cocoa-based "element" plugin for Sandvox.</string>
<key>FilesToMacroExpand</key>
<array>
<string>«PROJECTNAMEASIDENTIFIER»_Prefix.pch</string>
<string>en.lproj/InfoPlist.strings</string>
<string>«PROJECTNAMEASIDENTIFIER».icns</string>
<string>«PROJECTNAMEASIDENTIFIER»Delegate.h</string>
<string>«PROJECTNAMEASIDENTIFIER»Delegate.m</string>
<string>«PROJECTNAMEASIDENTIFIER»Template.html</string>
<string>Info.plist</string>
</array>
<key>FilesToRename</key>
<dict>
<key>___PROJECTNAMEASIDENTIFIER___.icns</key>
<string>«PROJECTNAMEASIDENTIFIER».icns</string>
<key>___PROJECTNAMEASIDENTIFIER___Delegate.h</key>
<string>«PROJECTNAMEASIDENTIFIER»Delegate.h</string>
<key>___PROJECTNAMEASIDENTIFIER___Delegate.m</key>
<string>«PROJECTNAMEASIDENTIFIER»Delegate.m</string>
<key>___PROJECTNAMEASIDENTIFIER___Template.html</key>
<string>«PROJECTNAMEASIDENTIFIER»Template.html</string>
<key>___PROJECTNAMEASIDENTIFIER____Prefix.pch</key>
<string>«PROJECTNAMEASIDENTIFIER»_Prefix.pch</string>
<key>___PROJECTNAME___.xcodeproj</key>
<string>«PROJECTNAME».xcodeproj</string>
</dict>
</dict>
</plist>