我正在尝试使用Xcode中的自定义文件/项目模板。
我设法得到一个简单的项目模板并运行,但我有2个问题:
1.模板文件不会自动添加到现有目标中-我必须手动添加它们
1.我的文件目前分组的方式,我希望他们,但他们最终在根目录的应用程序-我宁愿他们在 * 共享 * 虽然。
所以我想问的是:什么是plist项缺少1.自动添加文件到目标和2.是否将群组放入我的应用的 * 共享 * 群组?
下面是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>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条答案
按热度按时间icomxhvb1#
若要将文件放入嵌套文件夹中,节点字符串必须包括所有文件夹名称,并且Group必须是相同文件夹名称的数组。路径是文件相对于模板文件位置的路径。在我的例子中,我把文件放在与模板相同的文件夹中,所以Path只是文件名。
当我修改并运行您的模板时,我没有得到其他文件(TestApp,ContentView,Assets...)。我不知道你是怎么让他们出现的。此外,正如您所说,与模板一起添加的文件不会添加到目标中。
标准的multiPlatform.app模板只有一个祖先
multiPlatform.app.SwiftUI
。如果我只使用那个祖先,丢失的文件就会出现,所有的文件都会被添加到目标中。我还没有弄清楚目标在模板层次结构中的位置,但您已经以某种方式绕过了该模板。