views:

3631

answers:

2

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.

+21  A: 

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.

Chris Hanson
I changed the actual templates in /Developer .. I don't have a "Developer" folder in my library.
Mk12
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.
Chris Hanson
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
+10  A: 

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

Barry Wark
Thanks, that worked! You're a genius.
Greg
Thanks!
Mk12