Change templates in Xcode

XcodeMacosTemplatesXcode4xcode4.5

Xcode Problem Overview


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.

Xcode Solutions


Solution 1 - Xcode

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

Solution 2 - Xcode

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

Solution 3 - Xcode

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].

Solution 4 - Xcode

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!

Solution 5 - Xcode

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

Solution 6 - Xcode

In xcode 5.0.1:

1.Go->Applications

2.right click "xcode" application

3.chose "Show Package Contents"

4.contents/Developer/Library/Xcode/Templates

Solution 7 - Xcode

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

It's much easier than modifying the templates.

Solution 8 - Xcode

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.

Solution 9 - Xcode

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

Solution 10 - Xcode

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)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMisha MView Question on Stackoverflow
Solution 1 - XcodeChris HansonView Answer on Stackoverflow
Solution 2 - XcodepconcepcionView Answer on Stackoverflow
Solution 3 - XcodeBarry WarkView Answer on Stackoverflow
Solution 4 - Xcodev01peView Answer on Stackoverflow
Solution 5 - Xcodecarbo18View Answer on Stackoverflow
Solution 6 - XcodetanyanzhiView Answer on Stackoverflow
Solution 7 - XcodeChrisJFView Answer on Stackoverflow
Solution 8 - XcodeManavView Answer on Stackoverflow
Solution 9 - XcodeAlex CioView Answer on Stackoverflow
Solution 10 - XcodeDenis KutlubaevView Answer on Stackoverflow