使用自定义模板创建群组xcode 8

i34xakig  于 2023-02-25  发布在  其他
关注(0)|答案(2)|浏览(130)

我已经成功地创建了一个Xcode 8模板,它将响应这些操作:
1.您已经有一个正在工作的项目
1.要将自定义swift文件添加到此项目中

    • 如何逐步实现:**

我已在以下位置创建:

/Users/*YOUR_USER_NAME*/Library/Developer/Xcode/Templates/File Templates

文件夹名称Custom/Interactor.xctemplate
该文件夹中的文件:

  • ___文件库名称___交互器
  • TemplateInfo.plist
  • TemplateIcon.png
  • TemplateIcon@2x.png

因此,当我右键单击并创建新文件时,我将选择自定义文件:

上面的示例可以正常工作并创建我的自定义文件:

    • 我努力实现的目标:**

我正在尝试创建一个包含新的自定义文件的组。不需要实际的文件夹或复杂的任务,只需要一个包含实际文件的组。
所以最终的结果将是:

由于没有文档解释如何创建自定义模板,我使用了许多参考:一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个二个一个一个一个一个一个二个一个一个一个一个一个二个一个一个一个一个一个二个一个一个一个一个一个二个一个一个一个一个一个一个一个一个一个一个一个二个一个一个一个一个一个一个一个一个一个一个一个二个一个一个一个一个一个一个一个一个一个一个一个二个一个一个一个一个一个一个一个一个一个一个一个一个一个一个一个
下面是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>
    • 我尝试过的:**

我试着将this答案插入到我的TemplateInfo.plist中,但是没有任何React。在我看来,这可能与范围问题有关--也许我没有在正确的位置插入DefinitionsNodes键。我一直在努力解决的xml DefinitionsNodes代码片段:

<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>

那么我应该把钥匙插在哪里或者我做错了什么?

    • 任何**帮助将不胜感激。

谢谢。

biswetbf

biswetbf1#

如果这对某些人有帮助,这里有一个适用于Xcode 12.4的项目模板:

<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>Info.plist:UIMainStoryboardFile</string>
    <string>Info.plist:UIApplicationSceneManifest:UISceneStoryboardFile</string>
    <string>Some/MainCoordinator.swift</string>
    <string>Some/Other/TestClass.swift</string>
</array>
<key>Definitions</key>
<dict>
    <key>Some/MainCoordinator.swift</key>
    <dict>
        <key>Group</key>
        <array>
            <string>Some</string>
        </array>
        <key>Path</key>
        <string>MainCoordinator.swift</string>
    </dict>
    <key>Some/Other/TestClass.swift</key>
    <dict>
        <key>Group</key>
        <array>
            <string>Some</string>
            <string>Other</string>
        </array>
        <key>Path</key>
        <string>TestClass.swift</string>
    </dict>
</dict>

这个组是Some,里面有一个文件,里面还有一个子组叫Other,里面还有一个文件叫Other

结果

thigvfpy

thigvfpy2#

可以使用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>

您还需要提供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>

相关问题