Have you ever wondered why creating new projects is taking such a long time? You don't have to anymore. If you want to set up a new project template, which you can use for many more projects, I’ve prepared a quick startup guide on how to do it. So let’s dive in.
If you ever had the honor to set up a project for development, you know it takes a long time to do if you start from scratch. If you have any projects that you want to get inspired by, it takes a bit less time since you can copy and paste some basic architecture and extensions you will likely use, but it still takes quite a while. Especially if you try to keep some consistent project structure and naming in your company, this tool comes in handy since it takes away a lot of the human factor out of the equation. If only there were some tools to make your job easier. Well, I am here to show you that you might be in luck.
The primary use is to link files, create folders, in a specific order, with a dynamic file header. In this article, I will show you how to set up your project hierarchy using project templates.
There are file templates that allow you to create files in an existing project, and there are project templates for creating entire projects from scratch.
The differences between file templates and project templates and basic information about the Xcode templates are in my previous article on Medium. So make sure you read that one first.
To sum up, you need to navigate to this folder (if not existent, create it): /Users/$USER_NAME/Library/Developer/Xcode/Templates/Project Templates everything within the templates folder is going to be listed in your Project creation wizard when as long as it is in a valid format.
Here is how the project template that I’ve been working on looks. The path is just a matter of organization, but the important part is that the file has: the .xctemplate suffix, the Icon files, and the TemplateInfo.plist.
For the icons, you can choose any png and a copy of it with the suffix @2x.png.
The plist file is where the magic happens. Put all the files you want to use in your project template. Unless you link the file within the plist file, they do not show in the created project. The order in the folder is irrelevant since the plist file is going to set the final order.
To view the plist file, I am using Atom since it highlights the XML syntax of the file. If you are comfortable using another tool, it is up to you.
Everything up to definitions you can copy/paste, since it’s static for our simple template. Regardless I’ll give you a quick sum-up anyway:
Kind: states that it’s a project template opposite to a file template which is the only other option.
Identifier: This is the identifier of the template that should be unique and can be referred to from other templates to import it
Concrete: States if this template should be visible. You can hide it if you only use it as a part of other templates.
Ancestors: lists the ids of other templates from which this template inherits.
Definitions: States files that you’re going to refer to later on below in the nodes. You need to put all the files that you want to see in your projects in the definitions. The Path in the definition <dict> states where the desired file is located relative to your template directory. The Group in the definition <dict> states how the folder hierarchy will be after you create a new project using the template.
Nodes: States which files will the template create. If not stated otherwise, the order in which you write them will be the order in which your file hierarchy will be.
Hit save and try to create a folder using this template. You should see your custom templates at the very bottom of the project creation options in a separate section (The naming reflects your folder structure after the Templates folder)