While building production apps, efficiency rarely comes from writing less code. It comes from writing the same code fewer times.
This article explains how Xcode Templates can be used to automate repetitive setup, improve consistency, and significantly speed up everyday development. The ideas apply to any architecture or project style.
To ground the discussion, I’ll start with a real problem I encountered while working on my invocing app Reckord, and then walk through how Xcode File Templates became a practical solution.
Reckord is a production iOS app built with a strong emphasis on structure and consistency. The app follows The Composable Architecture (TCA), which encourages explicit, well-defined components.
This structure is powerful, but it comes with a tradeoff.
Every time I added a new screen or feature, I had to:
None of this was difficult. But all of it was repetitive.
I found myself copying boilerplate code from an existing feature, pasting it into a new file, and carefully renaming types. Over time, this workflow started to slow me down and introduced small but avoidable risks—missed renames, leftover references, or minor inconsistencies.
The problem wasn’t TCA. The problem was manual repetition.
That’s when I decided to move this repetition into the tooling itself.
Xcode already provides a mechanism to solve this exact problem: File Templates.
Instead of manually creating files and pasting code, Xcode File Templates allow you to:
In my case, I created:
From that point onward, adding a new feature in Reckord became a predictable, low-friction operation.
Xcode Templates are customizable file blueprints that appear in:
File → New → File…
A template can include:
When you select a template and provide a name, Xcode generates the file exactly according to the template definition.
This allows Xcode to work with your workflow instead of against it.
Although my motivation came from working with TCA, file templates are architecture-agnostic.
They are equally useful for:
Any time you notice repeated setup, file templates are worth considering.
At a high level, a template consists of:
.xctemplate directoryTemplateInfo.plist___FILEBASENAME___Custom templates are stored locally at:
~/Library/Developer/Xcode/Templates/Each folder inside this directory becomes a category in Xcode.
NOTE: If you do not find
Templatesdirectory then create by your self.
To support my workflow, I created a dedicated template group:
Templates/
└── The Composable Architecture(TCA)
├── TCAView.xctemplate
└── TCAReducer.xctemplate
This keeps arcitecture-specific templates organized and easy to find.
Inside The Composable Architecture(TCA) folder, I added a template folder named: TCAView.xctemplate. It contain two files: ___FILEBASENAME___.swift and TemplateInfo.plist
TIP: Xcode already ships with well-structured, production-ready templates that can be reused as a foundation. A practical approach is to copy the existing Swift file template provided by Xcode and customize it for your own needs. The standard Swift file template is located at: /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/MultiPlatform/Source/Swift File.xctemplate
Contains of ___FILEBASENAME___.swift file:
//___FILEHEADER___
import SwiftUI
import ComposableArchitecture
struct ___FILEBASENAMEASIDENTIFIER___: View {
@Bindable var store: StoreOf<___FILEBASENAMEASIDENTIFIER___Domain>
var body: some View {
Text("___FILEBASENAMEASIDENTIFIER___")
}
}
#Preview {
___FILEBASENAMEASIDENTIFIER___(
store: Store(
initialState: ___FILEBASENAMEASIDENTIFIER___Domain.State(),
reducer: {
___FILEBASENAMEASIDENTIFIER___Domain()
}
)
)
}Contains of TemplateInfo.plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SupportsSwiftPackage</key>
<true/>
<key>Kind</key>
<string>Xcode.IDEFoundation.TextSubstitutionFileTemplateKind</string>
<key>Description</key>
<string>A SwiftUI Custom TCA View with Preview</string>
<key>Summary</key>
<string>TCA View</string>
<key>SortOrder</key>
<string>1</string>
<key>Image</key>
<dict>
<key>FileTypeIcon</key>
<string>swift</string>
</dict>
<key>AllowedTypes</key>
<array>
<string>public.swift-source</string>
</array>
<key>Platforms</key>
<array/>
<key>DefaultCompletionName</key>
<string>TCAView</string>
<key>MainTemplateFile</key>
<string>___FILEBASENAME___.swift</string>
<key>Options</key>
<array>
<dict>
<key>NotPersisted</key>
<true/>
<key>Type</key>
<string>text</string>
<key>Description</key>
<string>The name of the view to create</string>
<key>Name</key>
<string>Name of View:</string>
<key>Required</key>
<true/>
<key>Identifier</key>
<string>productName</string>
</dict>
</array>
</dict>
</plist>Similarly, the TCAReducer.xctemplate contains a predefined structure.
Contains of ___FILEBASENAME___.swift file:
//___FILEHEADER___
import ComposableArchitecture
@Reducer
struct ___FILEBASENAMEASIDENTIFIER___ {
@ObservableState
struct State: Equatable {
}
enum Action: Equatable {
}
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
}
}
}
}Contains of TemplateInfo.plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SupportsSwiftPackage</key>
<true/>
<key>Kind</key>
<string>Xcode.IDEFoundation.TextSubstitutionFileTemplateKind</string>
<key>Description</key>
<string>A TCA View Reducer</string>
<key>Summary</key>
<string>TCA View Reducer</string>
<key>SortOrder</key>
<string>1</string>
<key>Image</key>
<dict>
<key>FileTypeIcon</key>
<string>swift</string>
</dict>
<key>AllowedTypes</key>
<array>
<string>public.swift-source</string>
</array>
<key>Platforms</key>
<array/>
<key>DefaultCompletionName</key>
<string>TCAView</string>
<key>MainTemplateFile</key>
<string>___FILEBASENAME___.swift</string>
<key>Options</key>
<array>
<dict>
<key>NotPersisted</key>
<true/>
<key>Type</key>
<string>text</string>
<key>Description</key>
<string>The name of the reducer to create</string>
<key>Name</key>
<string>Name of Reducer:</string>
<key>Required</key>
<true/>
<key>Identifier</key>
<string>productName</string>
</dict>
</array>
</dict>
</plist>All boilerplate is generated automatically, leaving only feature-specific logic to implement. After creating or updating templates, restarting Xcode is required.
Once Xcode restarts:
No copy-paste. No cleanup.
Xcode Templates are a small investment with long-term impact.
By moving repetitive setup into Xcode itself, you:
For me, solving this problem while building Reckord made templates an essential part of my development environment—and once set up, they quietly pay dividends every day.
Thank you for reading. If you have any questions feel free to follow me on X and send me a DM. If you enjoyed this article and would like to support me, Buy me a coffee.