Working on an iOS or macOS project in Xcode you typically create classes with the same structure over and over again.
I use coordinators so I am creating new
UIViewControllers, each time referencing RxSwift, having methods for setting up UI, bindings .. most of the time also containing a delegate for the coordinator.
Having to create files with the same structure over and over again manually is a waste of time, a much better solution is creating Xcode file templates for those files.
Xcode file templates
File template location
All the Xcode custom file templates are located in
~/Library/Developer/Xcode/Templates/File Templates and grouped into sections by their folder name. If you want Xcode to show a “Custom” section at the bottom of the new file dialog, just create a
~/Library/Developer/Xcode/Templates/File Templates/Custom folder.
File template structure
Each file template is a separate folder with a name ending in
.xctemplate. If you want to create a simple “Swift Class” file template, you have to create a folder named
Swift Class.xctemplate in
Each file template folder should contain at least 3 files:
TemplateInfo.plist- describing the template
TemplateIcon.png- icon shown in the Xcode new file dialog
___FILEBASENAME___.swift- the actual template file