为Xcode 13创建自定义项目模板

3

我正在尝试使用Xcode中的自定义文件/项目模板。

我已经成功创建了一个简单的项目模板,但是我有两个问题:

  1. 模板文件没有自动添加到现有目标中 - 我必须手动添加它们
  2. 我的文件当前按照我想要的方式进行分组,但它们最终会出现在应用程序的根目录中 - 虽然我更愿意将它们放在Shared中。

所以我想问的是:缺少哪些plist条目才能1.自动将文件添加到目标中,2.将组放置在我的应用程序的Shared组中?

这是TemplateInfo.plist(首先是编辑器视图,下面是原始代码):

enter image description here

这导致以下文件结构:

enter image description here

<?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>Nodes</key>
    <array>
        <string>extensions/Binding+Extensions.swift</string>
        <string>extensions/NavigationLink+Extensions.swift</string>
        <string>extensions/View+Extensions.swift</string>
    </array>
    <key>Definitions</key>
    <dict>
        <key>extensions/Binding+Extensions.swift</key>
        <dict>
            <key>Group</key>
            <string>extensions</string>
            <key>Path</key>
            <string>extensions/Binding+Extensions.swift</string>
            <key>SortOrder</key>
            <integer>99</integer>
        </dict>
        <key>extensions/NavigationLink+Extensions.swift</key>
        <dict>
            <key>Group</key>
            <string>extensions</string>
            <key>Path</key>
            <string>extensions/NavigationLink+Extensions.swift</string>
            <key>SortOrder</key>
            <integer>99</integer>
        </dict>
        <key>extensions/View+Extensions.swift</key>
        <dict>
            <key>Group</key>
            <string>extensions</string>
            <key>Path</key>
            <string>extensions/View+Extensions.swift</string>
            <key>SortOrder</key>
            <integer>99</integer>
        </dict>
    </dict>
    <key>Kind</key>
    <string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
    <key>Identifier</key>
    <string>ch.appfros.dt.unit.multiPlatform.app</string>
    <key>Ancestors</key>
    <array>
        <string>com.apple.dt.unit.base</string>
        <string>com.apple.dt.unit.languageChoice</string>
        <string>com.apple.dt.unit.crossPlatformBase</string>
    </array>
    <key>Concrete</key>
    <true/>
    <key>Description</key>
    <string>This template creates a multi-platform SwiftUI application.</string>
    <key>SortOrder</key>
    <integer>1</integer>
    <key>NameOfInitialFileForEditor</key>
    <string>ContentView.swift</string>
    <key>Image</key>
    <dict>
        <key>BundleImageName</key>
        <string>app</string>
        <key>BundleIdentifier</key>
        <string>com.apple.dt.IDEKit</string>
    </dict>
    <key>Platforms</key>
    <array/>
    <key>Options</key>
    <array>
        <dict>
            <key>Identifier</key>
            <string>languageChoice</string>
            <key>Override</key>
            <string>Swift</string>
        </dict>
        <dict>
            <key>Identifier</key>
            <string>userInterface</string>
            <key>Override</key>
            <string>SwiftUI</string>
        </dict>
        <dict>
            <key>Identifier</key>
            <string>appLifecycle</string>
            <key>Override</key>
            <string>SwiftUI</string>
        </dict>
        <dict>
            <key>Identifier</key>
            <string>hasUnitAndUITests</string>
            <key>Name</key>
            <string>Include Tests</string>
            <key>NotPersisted</key>
            <false/>
            <key>SortOrder</key>
            <integer>300</integer>
            <key>Type</key>
            <string>checkbox</string>
            <key>Default</key>
            <string>true</string>
            <key>Units</key>
            <dict>
                <key>false</key>
                <dict>
                    <key>Components</key>
                    <array>
                        <dict>
                            <key>Identifier</key>
                            <string>com.apple.dt.unit.multiPlatform.app.shared</string>
                            <key>Name</key>
                            <string>Shared</string>
                        </dict>
                        <dict>
                            <key>Identifier</key>
                            <string>com.apple.dt.unit.multiPlatform.app.iOS</string>
                            <key>Name</key>
                            <string>iOS</string>
                        </dict>
                        <dict>
                            <key>Identifier</key>
                            <string>com.apple.dt.unit.multiPlatform.app.macOS</string>
                            <key>Name</key>
                            <string>macOS</string>
                        </dict>
                    </array>
                </dict>
                <key>true</key>
                <dict>
                    <key>Components</key>
                    <array>
                        <dict>
                            <key>Identifier</key>
                            <string>com.apple.dt.unit.multiPlatform.app.shared</string>
                            <key>Name</key>
                            <string>Shared</string>
                        </dict>
                        <dict>
                            <key>Identifier</key>
                            <string>com.apple.dt.unit.multiPlatform.app.iOS</string>
                            <key>Name</key>
                            <string>iOS</string>
                        </dict>
                        <dict>
                            <key>Identifier</key>
                            <string>com.apple.dt.unit.multiPlatform.app.macOS</string>
                            <key>Name</key>
                            <string>macOS</string>
                        </dict>
                        <dict>
                            <key>Identifier</key>
                            <string>com.apple.dt.unit.multiPlatform.app.iOS.tests.ui</string>
                            <key>Name</key>
                            <string>Tests iOS</string>
                        </dict>
                        <dict>
                            <key>Identifier</key>
                            <string>com.apple.dt.unit.multiPlatform.app.macOS.tests.ui</string>
                            <key>Name</key>
                            <string>Tests macOS</string>
                        </dict>
                    </array>
                </dict>
            </dict>
        </dict>
        <dict>
            <key>Identifier</key>
            <string>coreData</string>
            <key>Name</key>
            <string>Use Core Data</string>
            <key>Description</key>
            <string>Whether the application should use the Core Data framework for storage</string>
            <key>SortOrder</key>
            <integer>200</integer>
            <key>Type</key>
            <string>checkbox</string>
            <key>Default</key>
            <string>false</string>
        </dict>
        <dict>
            <key>Identifier</key>
            <string>coreDataCloudKit</string>
            <key>Name</key>
            <string>Host in CloudKit</string>
            <key>Description</key>
            <string>Whether the application should use Core Data with CloudKit</string>
            <key>RequiredOptions</key>
            <dict>
                <key>coreData</key>
                <string>true</string>
            </dict>
            <key>Indented</key>
            <true/>
            <key>SortOrder</key>
            <integer>201</integer>
            <key>Type</key>
            <string>checkbox</string>
            <key>Default</key>
            <string>false</string>
            <key>Values</key>
            <array>
                <string>false</string>
                <string>true</string>
            </array>
            <key>Variables</key>
            <dict>
                <key>false</key>
                <dict>
                    <key>persistentContainerClass</key>
                    <string>NSPersistentContainer</string>
                    <key>usedWithCloudKitModelAttribute</key>
                    <string>false</string>
                </dict>
                <key>true</key>
                <dict>
                    <key>persistentContainerClass</key>
                    <string>NSPersistentCloudKitContainer</string>
                    <key>usedWithCloudKitModelAttribute</key>
                    <string>true</string>
                </dict>
            </dict>
        </dict>
    </array>
</dict>
</plist>

1个回答

0
把文件放入嵌套文件夹中,节点字符串必须包含所有文件夹名称,并且 Group 必须是相同文件夹名称的数组。Path 是相对于模板文件位置的文件路径。在我的情况下,我把文件放在与模板相同的文件夹中,所以 Path 只是文件名。 带有嵌套文件夹的模板 带有嵌套文件夹的 Xcode 当我修改和运行您的模板时,我没有得到其他文件(TestApp、ContentView、Assets...)。我不确定您是如何让它们显示的。另外,就像您说的那样,使用您的模板添加的文件未添加到目标中。
标准的multiPlatform.app模板只有一个祖先multiPlatform.app.SwiftUI。如果我只使用这个祖先,缺失的文件会出现,并且所有文件都会被添加到目标中。我还没有弄清楚在模板层次结构中目标是在哪里分配的,但你已经绕过了那个模板。 修改后的multiPlatform模板 带有目标的Xcode

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接