114

How would I change the initial templates created by Xcode when creating a new Cocoa Class.

I am referring to the comments and class name created when using Xcode's new class wizard.

0

10 Answers 10

113

You wouldn't change the existing templates. In other words, don't modify anything under the /Developer hierarchy (or wherever you installed your developer tools).

Instead, clone the templates you want to have customized variants of. Then change their names and the information in them. Finally, put them in the appropriate location in your account's Library/Application Support folder, specifically:

  • File templates: ~/Library/Application Support/Developer/Shared/Xcode/File Templates/
  • Target templates: ~/Library/Application Support/Developer/Shared/Xcode/Target Templates/
  • Project templates: ~/Library/Application Support/Developer/Shared/Xcode/Project Templates/

That way they won't be overwritten when you install new developer tools, and you can tweak them to your heart's content.

Update For newer versions of Xcode the updated path will be: ~/Library/Developer/Xcode/Templates/File Templates/Source

16
  • 6
    If you don't have the paths above, you can create them. Don't change the templates in /Developer, because they won't necessarily survive uninstall and reinstall of the tools. Treat it like /System. Commented Aug 23, 2009 at 1:06
  • 3
    I still just change the ones in /Developer because then it actually changes it instead of creating new ones which are almost the same. Using the home directory library doesn't overwrite the /Developer one, it considers it a different template. I only use the home library for creating new templates, not changing existing ones. I can remember to move the templates before installing a new xcode, and by the way its not ~/Library/Developer/...., its ~/Library/**Application Support/**Developer/...
    – mk12
    Commented Aug 28, 2009 at 20:45
  • 5
    In Xcode 4.5, the path here: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates
    – huyleit
    Commented Aug 14, 2013 at 1:05
  • 6
    In XCode5 you should copy templates to path: ~/Library/Developer/Xcode/Templates/Application/Project Templates. If Templates/Application/Project Templates not exists, create it
    – seufagner
    Commented Oct 12, 2013 at 5:28
  • 3
    If you want the template to appear under iOS too, then add "com.apple.platform.iphoneos" to the Platforms list in TemplateInfo.plist. Commented Feb 27, 2014 at 12:17
47

This may be useful for somebody:

As for XCode 6 to XCode 9 the file templates are in:

/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source

Update: As @carbo18 noted, it's proably better to create the directory ~/Library/Developer/Xcode/Templates/File Templates/Source and put your custom templates there. The best way may be to use as base one of the ones in /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source

2
  • 2
    It is better not to modify the content of the Xcode.app because Apple can just overwrite the template folders. A better option is to create the ~/Library/Developer/Xcode/Templates/File Templates/Source directory and put the template there. They will appear correctly in the dialog box.
    – carbo18
    Commented Jan 1, 2016 at 23:08
  • As of xcode 7.3.1 this doesn't appear to work anymore
    – Brynjar
    Commented Jun 1, 2016 at 8:22
34

Xcode uses template files for file and project templates and does variable expansion in both at creation time.

Xcode 3.0 templates can be found in [Dev Installation]/Library/Xcode/, likely /Developer/Library/Xcode. If you want to modify these templates or add your own, use the following directories to save your new/modified templates so that they are not wiped out by future Developer Tool upgrades:

  • File templates: ~/Library/Developer/Shared/Xcode/File Templates/
  • Target templates: ~/Library/Developer/Shared/Xcode/Target Templates/
  • Project templates: ~/Library/Developer/Shared/Xcode/Project Templates/

I think that you can also use the /Library/Developer/Shared/Xcode/[File|Target|Project] Templates/ directory for templates shared by all users.

If you just want to change the MyCompanyName in the templates, the following command line will do the trick:

defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ "ORGANIZATIONNAME" = "NewCompanyName";}'

A good tutorial on writing file templates is here [MacResearch.org].

1
13

In Xcode 4 and Xcode 5 the user file templates can be placed at:
~/Library/Developer/Xcode/Templates/[Category]

[Category] can be used to categorize your templates (choose a name of your choise)

If the folder doesn't exist already, create it!

1
  • 3
    @Dimitris: This are the internal templates… I was talking about the USER templates, if you want to create new ones or customized variants like Chris Hanson suggested, and don't mess around with the original ones.
    – v01pe
    Commented Jan 21, 2012 at 0:01
8

As of Xcode 7

  • File templates: ~/Library/Developer/Xcode/Templates/File Templates
  • Project templates: ~/Library/Developer/Xcode/Templates/Project Templates

For example if I place a Empty Application.xctemplate in ~/Library/Developer/Xcode/Templates/Project Templates/Application

It will appear in the template dialog as Template Dialog

4
  • If you change files to this folder, will they be overwritten when new versions of xCode are installed?
    – ajmccall
    Commented Feb 1, 2016 at 13:09
  • No they wouldn't since you are creating your own folder and this folder is empty by default and is there for that purpose. I do wish Apple would document this stuff better. There is a drawback to this method, since it is per user. You would have to copy the templates to each user on the computer, if there are many. But this would be uncommon, I think, since most developers have their own computer.
    – carbo18
    Commented Feb 7, 2016 at 21:28
  • How would I change the default UIViewController template for Swift files? Dropping a file in ~/Library/Developer/Xcode/Templates/File Templates named UIViewContoller.swift does not work.. Thx!
    – Lapidus
    Commented May 16, 2016 at 21:14
  • Adding a file template is a little more involved than just adding a swift file. The UIViewController.swift is actually created through the Cocoa Touch Template. If you want to look at what the Apple Template looks like so that you can create your own. Show the contents of the Xcode app. And Navigate to Contents/Developer/Library/Xcode/Templates/File Templates/Source and look at the Cocoa Class.xctemplate. Here you will get a better idea of how that template was created, you can then copy this template to the folder specified above and modify it to your specs.
    – carbo18
    Commented May 18, 2016 at 3:51
6

In xcode 5.0.1:

1.Go->Applications

2.right click "xcode" application

3.chose "Show Package Contents"

4.contents/Developer/Library/Xcode/Templates

2

Right click on xCode and select Show Package contents, then go to contents/Developer/Library/Xcode/Templates. Here you can find the templates for all programming languages.

Here some visualization:


enter image description here


enter image description here

2

If you are simply looking to change the Author Name and Organization see this answer.

It's much easier than modifying the templates.

1

For Xcode 4.4, none of the previously mentioned methods work. This gist provides a partial hacky solution. Please fork and enhance if you know a better way.

-8

In XCode 4.5 right click on project, click Show File Inspector, then change Organization name in the file inspector's second tab (Project Document group)

2
  • 4
    Just dead wrong but I can't down this vote until my reputation is 125, help me out guys!
    – Stu P.
    Commented May 9, 2013 at 18:31
  • @StuartP. joining the cause i guess Commented May 23, 2019 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.