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. Customizing a macro requires two things:
-
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.
Open desired the IDETemplateMacros.plist
file.
-
Add a new entry to the top level dictionary.
-
Set the key for the new entry to the name of the text macro you want to customize or to add.
-
Set the type of the new entry to String.
-
Set the value of the new entry to the desired text.
-
Save the file. Your macro is now available for use.
Choose File > New File.
Click on Property List and click Next.
Set the top level type to Dictionary.
Save the file as IDETemplteMacros.plist
in the desired location.
COPYRIGHT A copyright string that uses the company name of the team for the project. If there is no company name, the string is blank.
The example shows a copyright string when the company is set to “Apple”.
Copyright © 2017 Apple. All rights reserved.
DATE The current date.
DEFAULTTOOLCHAINSWIFTVERSION The version of Swift used for the default toolchain.
FILEBASENAME The name of the current file without any extension.
FILEBASENAMEASIDENTIFIER The name of the current file encoded as a C identifier.
FILEHEADER The text placed at the top of every new text file.
FILENAME The full name of the current file.
FULLUSERNAME The full name of the current macOS user.
NSHUMANREADABLECOPYRIGHTPLIST The entry for the human readable copyright string in the Info.plist file of a macOS app target. The value of the macro must include the XML delimiters for the plist. For example, a valid value is:
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 Apple, Inc. All rights reserved.</string>
Notice that the value includes a newline.
ORGANIZATIONNAME The company name for the team used for the provisioning profile.
PACKAGENAME The name of the package built by the current scheme.
PACKAGENAMEASIDENTIFIER A C-identifier encoded version of the package name built by the current scheme.
PRODUCTNAME The app name of the product built by the current scheme.
PROJECTNAME The name of the current project.
RUNNINGMACOSVERSION The version of macOS that is running Xcode.
TARGETNAME The name of the current target.
TIME The current time.
USERNAME The login name for the current macOS user.
UUID Returns a unique ID. The first time this macro is used, it generates the ID before returning it. You can use this macro to create multiple unique IDs by using a modifier. Each modifier returns an ID that is unique for that modifier. For example, the first time the UUID:firstPurpose modifier is used, the macro generates and returns a unique ID for that macro and modifier combination. Subsequent uses of the UUID:firstPurpose modifier return the same ID. Adding the UUID:secondPurpose modifier generates and returns a different ID that will be unique to UUID:secondPurpose, and different from the ID for UUID:firstPurpose.
WORKSPACENAME The name of the current workspace. If there is only one project open, then the name of the current project.
YEAR The current year as a four-digit number.
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 https://oleb.net/blog/2017/07/xcode-9-text-macros/