Custom Xcode Header Comment

«  Fix Cannot Find Header Files For Ruby Error
Introduction of Universal Links  »

Although Xcode default header might be good enough for some case, but sometimes, we might want to define our own Header Comment for our project.

For example, if you are in a project team, then the Created by xxx is not really helpful, since other team member might do some changes for this file in the later. And this author means nothing 😜. OR you might want to define your own Copyright for the project / company.

In these cases, we might want to define our own Header Comment.

By researching, Apple have this Text Macros things which could help us to do this.

Text Macros

Text macros are symbols that are expanded in-place to the specified text. They are used in files and other places in Xcode, such as the header text for a new file or the project name. You can customize existing macros and add your own macros in a project, for all users of a project, or for all of Xcode.

For adding this file, we need a IDETemplateMacros.plist file, which could be generated by:

  • New File
  • Under Resources, select Property List and name the file as IDETemplateMacros.plist

After adding it, the next step is changing its content. By open it with source code, it is easily to be replaced like ⬇️

<?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 "Your Name" on ___DATE___.
//  ___COPYRIGHT___
//
    </string>
</dict>
</plist>

It is easily to test it by just adding a new file into the project. It should be able to see ~

By putting it to different places, it will be applied to different group, you could simply check this list:

  • Project user data: .xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist.
  • Project shared data: .xcodeproj/xcshareddata/IDETemplateMacros.plist
  • Workspace user data: .xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist.
  • Workspace shared data: .xcworkspace/xcshareddata/IDETemplateMacros.plist.
  • User Xcode data: ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist.

For more complicated, such as: change date format OR change copyright. Here is a guide for text macros ~ 🎉

Reference

https://help.apple.com/xcode/mac/9.0/index.html?localePath=en.lproj#/dev91a7a31fc

https://help.apple.com/xcode/mac/9.0/index.html?localePath=en.lproj#/dev7fe737ce0

Published on 20 Jan 2020 Find me on Facebook, Twitter!

«  Fix Cannot Find Header Files For Ruby Error
Introduction of Universal Links  »

Comments

    Join the discussion for this article at here . Our comments is using Github Issues. All of posted comments will display at this page instantly.