我已经成功创建了一个适用于 Xcode 8 的模板,可以响应以下操作:
- 您已经有一个工作的项目
- 您想将自定义 Swift 文件添加到此项目中
步骤如下:
我在下面创建了:
/Users/*YOUR_USER_NAME*/Library/Developer/Xcode/Templates/File Templates
文件夹名称为Custom/Interactor.xctemplate
。
该文件夹内包含以下文件:
- ___FILEBASENAME___Interactor
- TemplateInfo.plist
- TemplateIcon.png
- TemplateIcon@2x.png
因此,当我右键创建新文件时,我会选择自定义文件:
上面的示例可以正常工作并创建我的自定义文件:
我想要实现的目标:
我想要创建一个包含新自定义文件的群组。不需要实际文件夹或复杂的任务,只需一个包含实际文件的群组即可。
因此,最终结果将是:
由于没有说明如何创建自定义模板的文档,因此我参考了许多资料:ref1、ref2、ref3、ref4。
这是TemplateInfo.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>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>
我的尝试:
我尝试将这个回答插入到我的 TemplateInfo.plist 中,但没有任何反应。我认为这可能与作用域有关 - 也许我没有把 Definitions
或 Nodes
键插入到正确的位置。我一直在努力解决的 xml Definitions
和 Nodes
代码片段:
<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>
那么我应该在哪里插入这些键或者我做错了什么?
任何帮助将不胜感激。
谢谢。