今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

Xcode project default text modification

Background#

Recently, I needed to modify the default project text in Xcode, which refers to the comment instructions generated at the top of each project creation. I remembered that when I downloaded code from the original Raywenderlich website (now Kodeco), each existing file had a long string of custom instructions, and new files also had the same custom instructions. I was curious about it before, but I didn't investigate it thoroughly. Today, I will study how to implement it:

The custom instructions in Kodeco files are as follows:

Kodeco Custom Instructions

Implementation#

By referring to Customize text macros and Text macros reference, it can be seen that the default header text comment in Xcode is defined as follows:


//  ___FILENAME___
//  ___PACKAGENAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  ___COPYRIGHT___
//

Then, referring to Customizing the file header comment and other text macros in Xcode 9, the modification steps are as follows:

  1. Create IDETemplateMacros.plist.
  2. Add or modify the Root corresponding to the type Dictionary.
  3. Then, referring to the meaning of the fields in Text macros reference, add the corresponding key (as the field name) and value (as the defined text).

The steps are not difficult, but it is necessary to distinguish where to place the IDETemplateMacros.plist file, referring to Customizing the file header comment and other text macros in Xcode 9:

  • For personal development, effective for a specific project, place it in:
    <ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
  • For multiple people, effective for a specific project, place it in:
    <ProjectName>.xcodeproj/xcshareddata/IDETemplateMacros.plist
  • For personal development, effective for all workspaces, place it in:
    <WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
  • For multiple people, effective for all workspaces, place it in:
    <WorkspaceName>.xcworkspace/xcshareddata/IDETemplateMacros.plist
  • For all projects on the computer, place it in:
    ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist

The specific placement location should be determined based on the actual usage scenario. For example, for the custom instructions in Kodeco files, it should be placed to be effective for all workspaces for multiple people. Another example is if you want to modify the "Created by" username for each new project on the computer without changing the computer username (which may be risky), you can use the last method to modify it, as shown below:

Modify Username

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.