Home About Notes

Xcode file templates

Apr 11, 2023

Create templates for the Xcode new file modal. Handy for teams that often have a similar starting point for new files

You can create templates for the Xcode new file modal. Handy for teams that often have a similar starting point for new files. eg. Import's, properties, or tests. The simplest example of how the template files work is the new Swift file. You can find it here:

/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/MultiPlatform/Source/Swift\ File.xctemplate

Create your own.

To make this template shareable copy paste & rename the Swift File.xctemplateinto your project folder into a folder that will end up being your section name in the Xcode new file modal. From here you can edit the files and get your perfect templates. To get an understanding of the types of things you can do, view all of Apple's templates in the Xcode.app folder listed above.

When you are ready to share it create a script that creates the folderĀ 

~/Library/Developer/Xcode/Templates/ 

and symlinks your folder in it.