今是昨非

今是昨非

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

Xcode Default Project Text Modification

Background#

Recently, there was a need to modify the default text in Xcode project creation, specifically the comment instructions that are generated at the top. I remembered that when I downloaded code from the original Raywenderlich (now Kodeco) website, each existing file had a long string of custom instructions, and new files also had the same custom instructions. I was curious about this, but 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, by referring to Customizing the file header comment and other text macros in Xcode 9, the following steps can be determined for modification:

  1. Create IDETemplateMacros.plist
  2. Add or modify the Root corresponding to 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 important to differentiate where the IDETemplateMacros.plist file should be placed, as referenced in Customizing the file header comment and other text macros in Xcode 9

  • For personal development specific to a Project, place it in:
    <ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
  • For multiple people specific to a Project, place it in:
    <ProjectName>.xcodeproj/xcshareddata/IDETemplateMacros.plist
  • For personal development applicable to all workspaces, place it in:
    <WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
  • For multiple people applicable to 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 apply to multiple people and all workspaces. Another example is if you want to modify the username in the "Created by" section of projects on your computer without changing the computer username (which may have risks), you can use the last method shown below:

Modifying Username

References#

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