---
title: "#89: Custom Xcode File Templates 🔨"
url: https://littlebitesofcocoa.com/89-custom-xcode-file-templates
author: Jake Marsh
date: 2015-09-24
published: 2015-09-24
topics: ["Tools"]
description: "Xcode ships with some great starter templates for projects, files, and even targets. Today we'll look at how to add our own custom file templates to Xcode's..."
---

# #89: Custom Xcode File Templates 🔨

By Jake Marsh, September 24, 2015. HTML: https://littlebitesofcocoa.com/89-custom-xcode-file-templates

**Xcode** ships with some great starter **templates** for **projects**, **files**, and even **targets**. Today we'll look at how to add our own _custom file templates_ to **Xcode's** built-in set. We'll be adding a new **template** for easily creating new **table view controllers** powered by [Static](http://git.io/statictv) (a static **table view** library we covered in [Bite #74](https://littlebitesofcocoa.com/74)).

We'll begin by creating a **folder** for our custom **templates** to live in. This will be: **~/Library/Developer/Xcode/Templates/File Templates/Custom**. We'll create a new **folder** in here called **Static Table View Controller.xctemplate**.

Then we'll need to create two **files**: One called **TemplateInfo.plist** to describe our new **template**, and another where our actual **template** content will live.

Let's start with **TemplateInfo.plist**. We'll create this using **Xcode** by selecting **File** > **New** > **File...** and then **Resources** > **Property List**. We'll call it **TemplateInfo.plist** (the name is important) and give it this content:

<img src="https://media.littlebitesofcocoa.com/bite-assets/089-custom-xode-file-templates-template-info-plist.png" style="max-width: 474px;" />

Then we'll select **File** > **New** > **File...** and select **Source** > **Swift File**. We'll name it **`__FILEBASENAME__.swift`** to match the value in our **TemplateInfo.plist**.

The **template's** content <i>almost</i> looks like normal **Swift** code, but contains **template tags** (which will get replaced and "filled in" at run time):

``` swift
//  Created by ___FULLUSERNAME___ on ___DATE___. ___COPYRIGHT___

import UIKit
import Static

class ___FILEBASENAMEASIDENTIFIER___: TableViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    
    dataSource.sections = [ Section(rows: [ Row(text: "Hello World") ]) ]
  }
}
```

Lastly, we'll add an **icon** for our new **template** by adding a **TemplateIcon.png** our **template** **folder**.

We can now press **⌘N** in **Xcode** to see our new template. Success!

<img src="https://media.littlebitesofcocoa.com/bite-assets/089-custom-xode-file-templates-success.png" style="max-width: 303px;" />

The example **template** we made here is [available for download here](https://media.littlebitesofcocoa.com/bite-assets/089-custom-xode-file-templates-template-example.zip).

**Update:** We cover _custom <i>project</i> templates_ in [Bite #90](https://littlebitesofcocoa.com/90).
