2

我一直在尝试为 MVVM 设计模式创建包含样板文件和代码结构的 Xcode 文件模板。

我使用 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>Kind</key>
        <string>Xcode.IDEFoundation.TextSubstitutionFileTemplateKind</string>
        <key>Description</key>
        <string>MVVM Module Template.</string>
        <key>Summary</key>
        <string>MVVM Module Template</string>
        <key>Options</key>
        <array>

            <dict>
                <key>Identifier</key>
                <string>productName</string>
                <key>Required</key>
                <true/>
                <key>Name</key>
                <string>Module Name:</string>
                <key>Description</key>
                <string>The module name.</string>
                <key>Type</key>
                <string>text</string>
                <key>Default</key>
                <string>Base</string>
            </dict>

            <dict>
                <key>Identifier</key>
                <string>View</string>
                <key>Name</key>
                <string>Also create View file for user interface</string>
                <key>Description</key>
                <string>Create a view file with the same name</string>
                <key>Type</key>
                <string>checkbox</string>
                <key>NotPersisted</key>
                <true/>
            </dict>

        </array>
    </dict>
</plist>

自定义模板的文件夹结构

问题是,当我选中复选框时,会创建 View 文件夹中的所有文件,但是当未选中复选框时,不会创建任何文件。

我该怎么做才能实现以下情况:

  • 未选中复选框时,从文件夹“源”生成源文件。
  • 选中复选框时,从文件夹“查看”生成源文件。
4

1 回答 1

2

您在选中复选框时这样做是正确的,但是当未选中复选框时,您需要将“源”更改为“默认”。

于 2018-08-21T14:47:17.707 回答