Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 956
Fattie Avatar asked Dec 01 '13 11:12

Fattie


People also ask

How do I create a header in Xcode?

To create a new file, choose File/New/File … which will open a template chooser in which you can select a header file, a C file, or a C++ file. If you select a C or C++ file, it will give you the option of also creating a header file with the same name.

How do I open a header file in Xcode?

Holding the Command key, click the import/include statement to view the header. Also, you can Command-click on a symbol to jump to the header file that defines it.


2 Answers

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.

like image 168
Swift Dev Journal Avatar answered Oct 04 '22 01:10

Swift Dev Journal


There's a post here with a detailed guide. To access the original templates, you'll need to open the Xcode app bundle as mentioned in Mark's answer.

http://meandmark.com/blog/2011/11/creating-custom-xcode-4-file-templates/

like image 32
abc123 Avatar answered Oct 04 '22 01:10

abc123