Create the Template
First create your template file in the same manner that you would create any file in Xcode.
Once in Xcode, click Command
n
to open the file selection view.
Some tokens you can use are as follows:
___FILEBASENAMEASIDENTIFIER______FILEHEADER____
Here is an example
//
// ___FILEHEADER____
//import Foundation
import XCTest
@testable import TimeFountain
import Alamofireextension TimeFountainTests {
func test___FILEBASENAMEASIDENTIFIER___() {
}
}
Place the template
Custom Templates Directory
~/Library/Developer/Xcode/Templates mkdir -p ~/Library/Developer/Xcode/Templates/File\ Templates/Custom Xcode
Run
cd ~/Library/Developer/Xcode/Templates
If the command fails run
mkdir -p ~/Library/Developer/Xcode/Templates/File\ Templates/Custom Xcode
2. Go to Finder.
Click hotkeys: Command
shift
g
Paste in that path, then click GO
.
You might see an empty version of this. If you don’t have the custom folder, add it. Then copy the following path and go to it using Finder.
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates
Now you can change the Swift file.xc...
folder to be named as you like. Let’s rename it to: ___FILEHEADER____Test.swift
or whatever you like, and let's open the file to paste our template!
Now when we create a file, we can search for our custom file.