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

18,483

Solution 1

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.

Solution 2

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/

Share:
18,483
Fattie
Author by

Fattie

Updated on June 03, 2022

Comments

  • Fattie
    Fattie about 2 years

    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

  • Dhruv Mullick
    Dhruv Mullick about 10 years
    @Mark, I've got a problem here. If I choose the GroupName C++ Class, then the changed template is displayed only when I create a new class from the existing project. The changed template is not used for Command Line project's main.cpp file. This problem has been asked here too, but there's no answer to it. Could you please address this one too? stackoverflow.com/questions/19473701/…
  • Swift Dev Journal
    Swift Dev Journal about 10 years
    @DhruvMullick, You have to create a project template and tell it to use the C++ class you created. The simplest way to do this would be to make a copy of Apple's C++ command-line tool project template and replace Apple's main.cpp file with your .h and .cpp files.
  • Dhruv Mullick
    Dhruv Mullick about 10 years
    Oh but there are no .h and .cpp files /Applications/Xcode.app/Contents/Developer/Library/Xcode/Tem‌​plates/Project Templates/Mac/Application/Command Line Tool.xctemplate Here's a screenshot of the folder imgur.com/2iZsDFz
  • Swift Dev Journal
    Swift Dev Journal about 10 years
    @DhruvMullick, I can't answer your questions sufficiently in a comment. All I can tell you is you need to create a project template to get your class files added when you create a new project. Creating custom project templates is a pain. I recommend asking a new question on how to add a C++ file to an Xcode project template.
  • Dhruv Mullick
    Dhruv Mullick about 10 years
    @MarkSzymczyk, I've added a new question explaining the problem. Custom Xcode project templates stackoverflow.com/q/24409406/2647199?sem=2
  • Swift Dev Journal
    Swift Dev Journal about 10 years
    @DhruvMullick, I placed all my knowledge of custom Xcode project templates in a blog post, Creating Custom Xcode 4 Project Templates. It's been years since I worked with custom project templates so I can't provide any further assistance.
  • Benjohn
    Benjohn over 8 years
    It looks like you can't actually replace the standard ones, you can just add in new ones? I was hoping that it might be possible for the project file to specify where templates should be taken from so that our SCM repo can have company templates in it and they'll "just work" when you're working on the company project, and not be there otherwise.
  • Swift Dev Journal
    Swift Dev Journal over 8 years
    @Benjohn If you want your templates to survive Xcode updates, creating your own templates is the way to go. You could conceivably replace the standard templates, but you would lose them when you install a new version of Xcode.
  • Benjohn
    Benjohn over 8 years
    @MarkSzymczyk Thanks – I was hoping for a mechanism in Xcode that allows the templates to appear replaced, but without actually replacing the template in the Xcode app's package – they'd be hidden, rather than deleted.
  • Adam Johns
    Adam Johns almost 8 years
    So no way to check this change into version control to easily share with team?
  • Swift Dev Journal
    Swift Dev Journal almost 8 years
    @AdamJohns I haven't tried using version control with file templates. At the very least you should be able to put the template folders up some place for people to download and install on their Macs.