Xcode 9 folder references with custom project template

时间:2023-01-17 10:37:12

In Xcode 9, when you create a group it creates a linked folder in the file system, too. 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中,当您创建组时,它也会在文件系统中创建链接文件夹。因此,您无需手动为每个组创建文件夹。关于Xcode 9中与组和文件夹相关的更改的一个很好的解释,请参阅此内容。

I have a custom Xcode project template which generates a project and adds loads of Swift boilerplate source files in custom folders. My problem is that I can only create group folders like this: Xcode 9 folder references with custom project template, 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项目模板,它生成一个项目并在自定义文件夹中添加大量Swift样板源文件。我的问题是我只能创建这样的组文件夹:,它代表一个与文件系统目录无关的组。这不好,因为如果您稍后在Xcode中重命名文件夹,它将对相应的文件系统目录没有影响。

My goal is to write an Xcode project template that adds my custom boilerplate swift files in real reference folders like this: Xcode 9 folder references with custom project template.

我的目标是编写一个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:

<?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:

它创建了一个这样的项目:

Xcode 9 folder references with custom project template

What I'd like to achieve:

我想要实现的目标:

Xcode 9 folder references with custom project template

Any help is much appreciated! :)

任何帮助深表感谢! :)

Update 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". It will build the folder structure with real reference folders.

我找到了一个小的解决方法..使用模板脚本创建自己的复杂文件夹层次结构然后只需删除根文件夹 - 在我的情况下为“类”。然后打开“废纸篓”并将其拖回Xcode,选择“复制项目(如果需要)”并选择“创建组”。它将使用真实的参考文件夹构建文件夹结构。

1 个解决方案

#1


0  

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>

#1


0  

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>