简体   繁体   English

带有自定义项目模板的 Xcode 9 文件夹引用

[英]Xcode 9 folder references with custom project template

In Xcode 9, when you create a group it creates a linked folder in the file system, too.在 Xcode 9 中,当您创建一个组时,它也会在文件系统中创建一个链接文件夹。 So you don't need to create folder for each group manually.所以你不需要手动为每个组创建文件夹。 A good explanation about the group and folder related changes in Xcode 9, see this .关于 Xcode 9 中组和文件夹相关更改的一个很好的解释,请参阅此

I have a custom Xcode project template which generates a project and adds loads of Swift boilerplate source files in custom folders.我有一个自定义 Xcode 项目模板,它生成一个项目并在自定义文件夹中添加大量 Swift 样板源文件。 My problem is that I can only create group folders like this:我的问题是我只能创建这样的组文件夹: 在此处输入图片说明 , which represents a Group not associated with a file system directory. , 表示与文件系统目录无关的组。 It's not good because if you later rename a folder in Xcode, it will have no effect on the corresponding file system directory.这不好,因为如果您以后在 Xcode 中重命名文件夹,它将对相应的文件系统目录没有影响。

My goal is to write an Xcode project template that adds my custom boilerplate swift files in real reference folders like this:我的目标是编写一个 Xcode 项目模板,将我的自定义样板 swift 文件添加到真正的参考文件夹中,如下所示: 在此处输入图片说明 . .

You can download my simplified template from here , place it under: ~/Library/Developer/Xcode/Templates你可以从这里下载我的简化模板,把它放在:~/Library/Developer/Xcode/Templates

Then Xcode > File > New > Project, and select Custom-Template.然后 Xcode > File > New > Project,然后选择 Custom-Template。

TemplateInfo.plist:模板信息.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.Xcode3.ProjectTemplateUnitKind</string>
    <key>Concrete</key>
    <true/>
    <key>Identifier</key>
    <string>custom-swift.xcodeTemplate</string>
    <key>Description</key>
    <string>Swift starter project for iOS projects</string>
    <key>Ancestors</key>
    <array>
        <string>com.apple.dt.unit.cocoaTouchFramework</string>
    </array>
    <key>Nodes</key>
    <array>
        <string>Classes/Interfaces/CustomInterface.swift</string>
    </array>
    <key>Definitions</key>
    <dict>
        <key>Classes/Interfaces/CustomInterface.swift</key>
        <dict>
            <key>Group</key>
            <array>
                <string>Classes</string>
                <string>Interfaces</string>
            </array>
            <key>Path</key>
            <string>Classes/Interfaces/CustomInterface.swift</string>
        </dict>
    </dict>
</dict>
</plist>

It creates a project like this:它创建了一个这样的项目:

在此处输入图片说明

What I'd like to achieve:我想达到的目标:

在此处输入图片说明

Any help is much appreciated!任何帮助深表感谢! :) :)

Update 1:更新 1:

I found a small workaround.. Create your own complex folder hierarchy with the template script then simply delete the root folder - in my case "Classes".我找到了一个小的解决方法.. 使用模板脚本创建您自己的复杂文件夹层次结构,然后简单地删除根文件夹 - 在我的例子中是“类”。 Then open the Trash and drag it back to Xcode, select "Copy items if needed" and select "Create groups".然后打开垃圾箱并将其拖回 Xcode,选择“如果需要复制项目”并选择“创建组”。 It will build the folder structure with real reference folders.它将使用真实的参考文件夹构建文件夹结构。

Here is what you need to do.这是您需要做的。 In the node section specify the group before naming the file.在命名文件之前在节点部分指定组。

<key>Nodes</key>
<array>
<string>MyGroup/File.swift:comments</string>
<array>

Next in the definitions provide the group name in the key like so:接下来在定义中提供键中的组名,如下所示:

<key>Definitions</key>
<dict>
<key>MyGroup/File.swift</key>
<dict>
<key>Path</key>
<string>File.swift</string>
<key>Group</key>
<string>MyGroup</string>
</dict>

Hopefully this will help.希望这会有所帮助。

For That purpose one can use Components as used in imessages template为此,可以使用 imessages 模板中使用的组件

Example of component is组件的例子是

<key>Components</key>
    <array>
        <dict>
            <key>Identifier</key>
            <string>com.apple.dt.unit.messagesextensioncomponentios</string>
            <key>Name</key>
            <string>___PACKAGENAME___ MessagesExtension</string>
            <key>ProductBuildPhaseInjections</key>
            <array>
                <dict>
                    <key>TargetIdentifier</key>
                    <string>com.apple.dt.messagesOnlyApp</string>
                </dict>
            </array>
        </dict>
    </array>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM