使用自定义模板XCode 8创建组 [英] Creating groups using a custom template xcode 8
问题描述
我已经成功创建了一个Xcode 8模板,该模板将响应以下操作:
I have successfully created an Xcode 8 template that will respond to these actions:
- 您已经有一个有效的项目
- 您要将自定义swift文件添加到该项目中
逐步介绍如何实现这一目标:
我在以下位置创建了
/Users/*YOUR_USER_NAME*/Library/Developer/Xcode/Templates/File Templates
文件夹名称Custom/Interactor.xctemplate
该文件夹中的文件:
- ___ FILEBASENAME ___ Interactor
- TemplateInfo.plist
- TemplateIcon.png
- TemplateIcon@2x.png
因此,当我右键单击并创建新文件时,我将选择自定义文件:
So when I right click and create new file, I will choose the custom file:
上面的示例可以工作并创建我的自定义文件:
The above example works and creates my custom file:
我要实现的目标:
我正在尝试创建一个包含新的自定义文件的组.不需要实际的文件夹或复杂的任务,只需一个包含实际文件的组即可.
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.
因此最终结果将是:
由于没有文档说明如何创建自定义模板,因此我使用了许多参考资料: ref2 , ref3 , ref4 .
Since there is no documentation explaining how to create a custom template I have used many references: 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
代码片段:
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 ?
任何帮助将不胜感激.
谢谢.
推荐答案
您可以使用此方法在项目目录中创建组和文件夹
you can create group as well as folder in project directory using this
<key>Swift</key>
<dict>
<key>Nodes</key>
<array>
<string>ViewController.swift:comments</string>
<string>ViewController.swift:imports:importCocoa</string>
<string>ViewController.swift:implementation(___FILEBASENAME___: UIViewController)</string>
<string>ViewController.swift:implementation:methods:viewDidLoad(override func viewDidLoad(\))</string>
<string>ViewController.swift:implementation:methods:viewDidLoad:super</string>
<string>ViewController.swift:implementation:methods:didReceiveMemoryWarning(override func didReceiveMemoryWarning(\))</string>
<string>ViewController.swift:implementation:methods:didReceiveMemoryWarning:super</string>
<string>Constant/CommonExtension.swift</string>
</array>
</dict>
和这样的定义
<key>Definitions</key>
<dict>
<key>Base.lproj/Main.storyboard</key>
<dict>
<key>Path</key>
<string>Main.storyboard</string>
<key>SortOrder</key>
<integer>99</integer>
</dict>
<key>Group</key>
<array>
<string>Singletone</string>
</array>
<key>Constant/CommonExtension.swift</key>
<dict>
<key>Path</key>
<string>Constant/CommonExtension.swift</string>
<key>Group</key>
<array>
<string>Constant</string>
</array>
</dict>
</dict>
这篇关于使用自定义模板XCode 8创建组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!