在Xcode中创建自定义模板 - 如何根据复选框创建所需选项?

时间:2013-02-14 20:31:54

标签: ios xcode cocoa-touch templates plist

我正在尝试在Xcode中创建自定义模板。在我的TemplateInfo.plist中,对于键选项,我将代码粘贴在下面。该模板将用于一个类,当事件发生时,通常会(但不总是)使用委托。

我遇到的问题是最底层的值,RequiredOptions。我希望仅当选中withProtocol复选框时才启用文本框。但是,我无法弄清楚要使用的值和值的类型。我尝试过以下方法:

  • <true/>(如下所示) - 始终启用文本框。
  • <string>YES</string> - 始终禁用文本框。
  • <integer>1</integer> - 始终启用文本框。

有没有人对我还能尝试什么有任何想法?更好的是,有没有人知道Xcode模板的一个不错的参考?

我已经阅读了Apple的plist手册页和this website上的文章。

<array>
    <dict>
        <key>Description</key>
        <string>The name of the class to create</string>
        <key>Identifier</key>
        <string>productName</string>
        <key>Name</key>
        <string>Class</string>
        <key>NotPersisted</key>
        <true/>
        <key>Required</key>
        <true/>
        <key>Type</key>
        <string>text</string>
    </dict>
    <dict>
        <key>Default</key>
        <string>false</string>
        <key>Identifier</key>
        <string>withXIB</string>
        <key>Name</key>
        <string>With XIB for user interface</string>
        <key>Type</key>
        <string>checkbox</string>
    </dict>
    <dict>
        <key>Description</key>
        <string>Choose whether or not a delegate skeleton is included.</string>
        <key>Default</key>
        <string>false</string>
        <key>Identifier</key>
        <string>withProtocol</string>
        <key>Name</key>
        <string>With delegate skeleton</string>
        <key>Type</key>
        <string>checkbox</string>
    </dict>
    <dict>
        <key>Description</key>
        <string>The name of the protocol used for delegation.</string>
        <key>Identifier</key>
        <string>protocolName</string>
        <key>Name</key>
        <string>Protocol</string>
        <key>NotPersisted</key>
        <true/>
        <key>Required</key>
        <true/>
        <key>Type</key>
        <string>text</string>
        <key>RequiredOptions</key>
        <dict>
            <key>withProtocol</key>
            <true/>
        </dict>
    </dict>
</array>

2 个答案:

答案 0 :(得分:2)

我通过将<true/>替换为<string>true</string>修复了我自己的问题。

答案 1 :(得分:0)

基于复选框添加所需选项的正确方法

RequiredOptions字典的键必须是另一个选项的标识符,并且字典的值必须是允许启用当前选项的选项值子集的数组。

<key>RequiredOptions</key>
<dict>
    <key>withXIB</key>
    <array>
        <string>true</string>
    </array>
</dict>

对于您来说,true完成了工作。

在Xcode 12上测试✅