Changing the default header comment license in Xcode

Xcode

Xcode Problem Overview


Whenever I create a new .cpp/.h file in Xcode a comment is added to the top of the file. For example:

/*
 *  <file>.cpp
 *  <Name of project>
 *
 *  Created by <My name> on <Date>.
 *  Copyright <Year and company>. All rights reserved.
 *
 */

I want to change the default comment to be another license, like GPL/LGPL/ or something else. Is there somewhere I can change this behavior in Xcode?

Xcode Solutions


Solution 1 - Xcode

With Xcode 9 there is a built-in option which you can find in the details below.

  1. Create a property list file named IDETemplateMacros.plist
  2. Add a FILEHEADER value to the Root and set its string value with your copyright text like Copyright © 2017 ...
  3. Copy the file to one of the following locations
    • For a single project and user <ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
    • For all team members in a single project <ProjectName>.xcodeproj/xcshareddata/IDETemplateMacros.plist
    • For all projects in a workspace for a single user <WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
    • For all projects in a workspace for all team members <WorkspaceName>.xcworkspace/xcshareddata/IDETemplateMacros.plist
    • For everything you work on, regardless of project ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist
  4. Create a new file - you should see the new copyright header

Sample IDETemplateMacros.plist for copy and paste:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>FILEHEADER</key>
	<string>
//  Created by Your Name on 29.12.17.
//  Copyright © 2017 Your Company. All rights reserved.
//  </string>
</dict>
</plist>

Solution 2 - Xcode

First try changing your Name and Organization your contact card in Address Book.

If that doesn't work, open System Preferences > Users & Groups > Right click on your user (System Preferences must already be unlocked) > Advanced Options... > Change the name in the Full Name text box.

To change the organization name in Xcode click on the project file so it is selected (left sidebar of Xcode in the Project navigator) > In the File Inspector (right sidebar of Xcode) change the Organization text box.

Organization text box

Solution 3 - Xcode

This blog post has some good steps for modifying file templates in Xcode 4.3:

http://error-success.piku.org.uk/2012/04/27/how-to-make-xcode-4-3-2-templates/

The /Developer folder no longer exists, so you copy the templates from within the Xcode.app bundle located in /Applications:

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

And place your modified copy here, as before:

~/Library/Developer/Xcode/Templates/File\ Templates/

UPDATE: I decided to write a script that would extract the built in Xcode templates and replace the headers. Source and instructions can be found at the following url:

https://github.com/royclarkson/xcode-templates

Solution 4 - Xcode

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

any update of your SDK will wipe changes here so keep your template backed up somewhere else

Solution 5 - Xcode

Don't edit anything in /Developer as Apple can overwrite this at any time.

The following works for Xcode 4, 5 and 6 except later source differs and is under /Applications

Instead copy the templates that you want to change from /Applications/Xcode<version>.app/Contents/Developer/Library/Xcode/Templates to ~/Library/Developer/Xcode/Templates/File Templates and then edit the files keeping the same directory structure but edit the directory name that is the template to not show up a a duplicate in Xcode.

e.g for a new category of C/C+ files in Xcode 5 copy /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/C and C++ to ~/Library/Developer/Xcode/Templates/File Templates/GPL C and C++

this process is copied from Red Glasses's blog

For Xcode 4 the source path is or for Xcode 4 /Developer/Library/Xcode/Templates/File Templates

Solution 6 - Xcode

– Press ⌘ 1 to display the File Navigator.
– Click on the name of your project at the top of the File Navigator.
– Press ⌘⌥⇧ ⏎ (that's Command Option Shift Return) to view the Version Editor.
– Make sure that the Comparison View is shown(View > Version Editor > Show Comparison View).

This lets you see the raw text of your project's project.pbxproj file.

– Press ⌘ f to search the project.pbxproj file, paste in ORGANIZATIONNAME and press Return.

This is where the name of the organization that follows the copyright text is defined.


Or open Xcode's plist at

~/Library/Preferences/com.apple.dt.Xcode.plist

And change the organizationName key's value.


Or select the project from the Navigator pane and display the File Inspector with ⌘⌥ 1.

Look at the Organization value under Project Document. Change the value there.

Solution 7 - Xcode

In Xcode 12.4

Using Xcode, create a plist file named IDETemplateMacros.

Save it to the Desktop initially while you configure it.

If you cannot see the file in the Project Navigator then from the Xcode menu, select View > Navigators > Project

Right click on the filename and select Open as > Source Code

The following is a template that works nicely for me so chances are it will for you too.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>FILEHEADER</key>
        <string>
//
// ___FILENAME___
// ___PACKAGENAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___
// Copyright © ___YEAR___ ___FULLUSERNAME___. All rights reserved.
//
        </string>
    </dict>
</plist>

Copy and paste the above overwriting the existing contents.

Save the file and close it.

In Finder navigate to the following folder:

~/Library/Developer/Xcode/UserdData/

Drag the file from your Desktop to this Folder and then test using Xcode to create a new project.

Solution 8 - Xcode

It's very simple:

  1. Open up terminal

  2. In one line, write the following:

     defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions -dict ORGANIZATIONNAME "Blah, Inc"
    

You don't have to worry about changing directories beforehand or anything else. It works instantly.

Solution 9 - Xcode

Change the details in your Address Book - add a company name. It will pick it up from there.

Solution 10 - Xcode

Try modifying this file:

/Developer/Library/Xcode/File\ Templates/C\ and\ C++/Header\ File.pbfiletemplate/header.h

Solution 11 - Xcode

In Xcode 4.2, they're here:

/Developer/Library/Xcode/Templates/File Templates

Solution 12 - Xcode

For AppCode users:

  1. Go to preferences (CMD + ,)
  2. Editor-File and Code Templates
  3. Change Scheme to Project
  4. Modify Files and/or Includes as you need.
  5. add to git .idea/fileTemplates if needed

Solution 13 - Xcode

I just changed the template of a SwiftUI file, you have to open Xcode's Contents and look for the template files you want to change. To change the SwiftUI template the path is this:

/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/MultiPlatform/User\ Interface/SwiftUI\ View.xctemplate

You nedd open with sudo

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
QuestionErik RothoffView Question on Stackoverflow
Solution 1 - XcodeabdullahselekView Answer on Stackoverflow
Solution 2 - XcodeChrisJFView Answer on Stackoverflow
Solution 3 - XcodeRoy ClarksonView Answer on Stackoverflow
Solution 4 - XcodeconorgriffinView Answer on Stackoverflow
Solution 5 - XcodemmmmmmView Answer on Stackoverflow
Solution 6 - XcodeAlex ZavatoneView Answer on Stackoverflow
Solution 7 - XcodeChrispyView Answer on Stackoverflow
Solution 8 - XcodeEric BrottoView Answer on Stackoverflow
Solution 9 - XcodebandejapaisaView Answer on Stackoverflow
Solution 10 - XcodecitView Answer on Stackoverflow
Solution 11 - XcodeDanyal AytekinView Answer on Stackoverflow
Solution 12 - XcodeKirowView Answer on Stackoverflow
Solution 13 - XcodeAlley PereiraView Answer on Stackoverflow