Totally change entire "header" on ALL new files in Xcode

Fattie picture Fattie · Dec 1, 2013 · Viewed 18.1k times · Source

When you create any file in Xcode you get:**

enter image description here

Is there a way to completely CHANGE that template?

(It's trivial to change the corporate name, etc. How to change the actual template?)

I do not care, at all, if I have to redo the change each time Xcode is upgraded.


FYI Years later, correct solution - https://stackoverflow.com/a/57510348/294884

Answer

Mark Szymczyk picture Mark Szymczyk · Dec 2, 2013

The file template creation process did not change in Xcode 5 so any information you found for Xcode 4 should also work in Xcode 5. But to answer your question, you have to create a custom file template. Duplicate one of Apple's file templates, which are in Xcode's application bundle. The iOS file templates are in the following location in Xcode 5:

Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates

The rest of Apple's file templates are in the following location in Xcode 5:

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

Selecting the Xcode application from the Finder, right-clicking, and choosing Show Package Contents will take you to the Contents directory inside the application bundle.

Place your copy of the file template in the following location:

/Users/YourUsername/Library/Developer/Xcode/Templates/File Templates/GroupName

GroupName is the name of the category on the left side of the New File Assistant. You can create your own group name or use one of the built-in names. Your file template will appear in the GroupName category.

Now it's time to edit your copy of Apple's file template. Inside the .xctemplate folder you should see the following files for Objective-C file templates:

___FILEBASENAME___.h
___FILEBASENAME___.m

There are triple underscores before and after FILEBASENAME. Open the FILEBASENAME files in Xcode and modify them to suit your needs. In your case that would involve changing the comments at the top of the file.

Whether or not creating custom file templates is practical depends on how many of Apple's file templates you want to duplicate. Duplicating every one of Apple's file templates would be impractical, but duplicating Apple's Cocoa Touch file templates would be more practical.