Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: enter image description here, 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: enter image description here.

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:

enter image description here

What I'd like to achieve:

enter image description here

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.

like image 608
balazs630 Avatar asked May 20 '18 11:05

balazs630


People also ask

How do I import a folder into an Xcode project?

I include them in the project by right-clicking on the project folder in the project view in Xcode, and selecting "Add Files to ...". I then navigate to the folder containing the source files, click on the folder and select "Add." With the options "Create folder references" and "Add to target [target name]".

What is create folder references Xcode?

Xcode creates a group in the Project navigator for each folder you add, and it adds the contents of the folder to that group. Create folder references. Displays the folders in the Project navigator, but doesn't copy them to the project. In the Project navigator, each added folder points to a folder in the file system.

Where are Xcode templates stored?

They are located in Xcode. app/Contents/Developer/Library/Xcode/Templates or Xcode. app/Contents/Developer/Platforms/<platform_name>/Developer/Library/Xcode/Templates.

What is project Navigator in Xcode?

After you have created your project in Xcode, the Xcode workspace displays the Project navigator. The Navigator area is an optional area on the left side of the Workspace window where you can load different navigators — including the Project navigator — with the help of the Navigator selector.


Video Answer


1 Answers

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.

like image 127
8azan Avatar answered Sep 18 '22 00:09

8azan