I have successfully created an Xcode 8 template that will respond to these actions:
- You already have a working project
- You want to add your custom swift file to this project
Step by step, how to achieve that:
I have created under:
/Users/*YOUR_USER_NAME*/Library/Developer/Xcode/Templates/File Templates
The folder name Custom/Interactor.xctemplate
Files inside that folder:
- ___FILEBASENAME___Interactor
- TemplateInfo.plist
- TemplateIcon.png
- [email protected]
So when I right click and create new file, I will choose the custom file:
The above example works and creates my custom file:
What I am trying to achieve:
I am trying to create a group that will contain the new custom file. No need for an actual folder or complicated tasks, simply a group that contains the actual file.
So the end result will be:
Since there is no documentation explaining how to create a custom template I have used many references: ref1, ref2, ref3, ref4.
Here is the TemplateInfo.plist
file:
<?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>DefaultCompletionName</key>
<string>MyCustomInteractor</string>
<key>Description</key>
<string>Custom interactor</string>
<key>Kind</key>
<string>Xcode.IDEKit.TextSubstitutionFileTemplateKind</string>
<key>Options</key>
<array>
<dict>
<key>Description</key>
<string>Custom interactor</string>
<key>Identifier</key>
<string>fileName</string>
<key>Name</key>
<string>Custom name</string>
<key>NotPersisted</key>
<true/>
<key>Required</key>
<true/>
<key>Type</key>
<string>text</string>
</dict>
<dict>
<key>Default</key>
<string>___VARIABLE_fileName:identifier___</string>
<key>Identifier</key>
<string>productName</string>
<key>Type</key>
<string>static</string>
</dict>
<dict>
<key>Default</key>
<string>___VARIABLE_fileName:identifier___Interactor</string>
<key>Description</key>
<string>The interactor name</string>
<key>Identifier</key>
<string>interactorName</string>
<key>Name</key>
<string>Interactor Name:</string>
<key>Required</key>
<true/>
<key>Type</key>
<string>static</string>
</dict>
</array>
<key>Platforms</key>
<array>
<string>com.apple.platform.iphoneos</string>
</array>
<key>SortOrder</key>
<string>99</string>
</dict>
</plist>
What I have tried:
I have tried to insert this answer into my TemplateInfo.plist but nothing happens. In my opinion it could be related to a scope issue - perhaps I am not inserting the Definitions
or the Nodes
keys in the right place. The xml Definitions
and Nodes
code snip I have been struggling with:
<key>Definitions</key>
<dict>
<key>___FILEBASENAME___Interactor.swift</key>
<dict>
<key>Group</key>
<string>Custom Interactor</string>
<key>Path</key>
<string>___FILEBASENAME___Interactor.swift</string>
</dict>
</dict>
<key>Nodes</key>
<array>
<string>___FILEBASENAME___Interactor.swift</string>
</array>
So where should I insert those keys or what am I doing wrong ?
Any help would be much appreciated.
Thanks.
Definitions
andNodes
are only taken into account for project templates, and adding the file into a folder in the Template makes XCode to import the folder instead of creating a group... – Remodel