Oha*_*adM 15 xcode templates xcode-template xcode8
我已经成功创建了一个响应这些操作的Xcode 8模板:
一步一步,如何实现:
我创建于:
/Users/*YOUR_USER_NAME*/Library/Developer/Xcode/Templates/File Templates
Run Code Online (Sandbox Code Playgroud)
文件夹名称 Custom/Interactor.xctemplate
该文件夹中的文件:
因此,当我右键单击并创建新文件时,我将选择自定义文件:
上面的示例工作并创建我的自定义文件:
我想要实现的目标:
我正在尝试创建一个包含新自定义文件的组.不需要实际的文件夹或复杂的任务,只需要包含实际文件的组.
所以最终结果将是:
由于没有解释如何创建自定义模板的文档,我使用了很多引用: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>
Run Code Online (Sandbox Code Playgroud)
我尝试过的:
我试图将这个答案插入我的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>
Run Code Online (Sandbox Code Playgroud)
那么我应该在哪里插入这些键或者我做错了什么?
任何帮助将不胜感激.
谢谢.
小智 1
您可以使用字典在项目目录中创建组和文件夹Nodes:
<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>
Run Code Online (Sandbox Code Playgroud)
您还需要提供Definitions,就像这样:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3016 次 |
| 最近记录: |