简体   繁体   中英

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. 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 .

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: 在此处输入图片说明 , 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.

My goal is to write an Xcode project template that adds my custom boilerplate swift files in real reference folders like this: 在此处输入图片说明 .

You can download my simplified template from here , place it under: ~/Library/Developer/Xcode/Templates

Then Xcode > File > New > Project, and select 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:

在此处输入图片说明

What I'd like to achieve:

在此处输入图片说明

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.

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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