Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Last active May 17, 2024 05:36
Show Gist options
  • Save brennanMKE/660171e9dfa16892b41f4bc0b3a7410f to your computer and use it in GitHub Desktop.
Save brennanMKE/660171e9dfa16892b41f4bc0b3a7410f to your computer and use it in GitHub Desktop.
Xcode File Header Templates

Xcode File Header Templates

Each time a new file is added in Xcode a header is added to the top. This is a good place to put a license or copywrite message. Xcode does support templates which are covered below. Placing a file named IDETemplateMacros.plist at one of the paths listed below with the contents which include FILEHEADER.

The string value can also include placeholders covered by Text macros reference with some listed below. Wrap each text macro with 3 underscores to include them in the output.

  • FILENAME
  • DATE
  • YEAR
  • ORGANIZATIONNAME
  • PACKAGENAME
  • PACKAGENAMEASIDENTIFIER
  • PRODUCTNAME
  • PROJECTNAME
  • WORKSPACENAME

The sample IDETemplateMacros.plist included with this gist shows that a value for the text macro can be set, such as ORGANIZATIONNAME. Newly created files in any Swift packages or Xcode projects in this workspace will inherit this file header template and will be used if another template is defined.

Below are the docs from Apple which and are copied here in case they are ever removed as others have been.

Customize text macros

  • A plist named IDETemplateMacros.plist at an appropriate location.
  • An entry in IDETemplateMacros.plist for the text macro.

Xcode looks for the value of a text macro in the following locations and uses the first matching macro:

Project user data: <ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist

Project shared data: <ProjectName>.xcodeproj/xcshareddata/IDETemplateMacros.plist

Workspace user data: <WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist

Workspace shared data: <WorkspaceName>.xcworkspace/xcshareddata/IDETemplateMacros.plist

User Xcode data: ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist

<?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>
// Copyright © ___YEAR___ ___ORGANIZATIONNAME___.
// All Rights Reserved.
</string>
<key>ORGANIZATIONNAME</key>
<string>ACME</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment