Using Xcode custom file templates with GIT

Xcode custom file templates are a great way to develop just a bit faster and enable you to define a base template with all repetitive work included. Combining it with GIT enables you to share these files in your team and let them benefit as well.

Creating a GIT repository for Xcode custom file templates

User-defined templates for Xcode are located in ~/Library/Developer/Xcode/Templates/File Template. If such folder is missing you can create it yourself and Xcode will be linked to it upon restarting. Subfolders can be used to create a custom header for your templates.

Create a subfolder for your GIT repository and use this new location for your custom templates.

Xcode Custom File Templates

Xcode Custom File Templates

Create your first custom file template

There are lots of great resources to learn how to create your own custom file templates. Some examples are:

But for me, the easiest way is to copy a base template from Xcode which I’m already familiar with. You can find them easily by opening the terminal and execute the following line for generic templates:

open /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates

Or the following line for platform specific templates, replacing #platform_name# with the platform you want to explore:

open /Applications/Xcode.app/Contents/Developer/Platforms/#platform_name#/Developer/Library/Xcode/Template

You can push your changes to the GIT repository after you’ve created your first custom file template. Your team will be able to make use of them by fetching the latest changes.