Published on

Templates in Xcode


If you catch yourself doing anything more than once in programming it's a sign. Let's take a look at Xcode's templates and see how we can use them to our advantage.

The Basics

Xcode has built-in templates located at:

/Applications/ Templates/

If you open one of the files inside the Source folder you'll see some pretty familiar names. By opening one of the files in your favorite text editor you'll see some pretty cool things right off the bat. First you'll see that there are keywords surrounded by triple underscores that are replaced with actual content when created inside your Xcode project.

By changing the contents of this file and saving it, you'll see the effects inside Xcode when creating a new file. This is especially useful if you're very active in the Open Source community and you want to leave a license at the top, or more information about the repository.

There are plenty of files to modify in this directory for both Objective-C and Swift, one of the must-have-edits involves removing the silly comment from the Swift Playground as well as the str variable in:

/Application/ Templates/Source/Playground.xctemplates/___FILEBASENAME___.playground


The other day I had copied a snippet from one of my projects and pasted it into Google Chrome and found that the "tab-tokens" are simply a trick! I found that I can easily piggyback on this format to make my own tab-tokens!

Piggybacked Template

To create one, just surround the text with <# #> (<# Like this #>) You can then press Tab and Shift + Tab to go back and forth! It's great for small changes in code that have a similar setup.