Xcode file header comments template

When you create a file using Xcode, comments are automatically generated at the top of the file

//
// AppDelegate.h
// SampleApp
//
// Created by xxx on 2021.
// Copyright © 2021 XXXXX. All rights reserved.
//
Copy the code

The information comes from the ~ / Library/Developer/Xcode/UserData/IDETemplateMacros plist FILEHEADER field values

Idetemplatemacros. plist contains the following contents


      
<! DOCTYPEplist PUBLIC "- / / / / DTD PLIST Apple 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 ___USERNAME___ on ___YEAR___. / / Copyright © ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved. //</string>
</dict>
</plist>
Copy the code

If ~ / Library/Developer/Xcode/UserData/directory no IDETemplateMacros plist, you need to create your own one

Different projects use different templates

Xcode looks for idetemplatemacros.plist from the following locations and loads the first plist found, so you can use this to configure different annotation templates for different projects.

<! --<ProjectName> is the ProjectName, [username] is the current username of the system, and <WorkspaceName> is the WorkspaceName -->The Project user data file path:<ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist. Project shared data file path:<ProjectName>. Xcodeproj/xcshareddata/IDETemplateMacros. Third, plist Workspace user data file path:<WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist. Workspace shared data file path:<WorkspaceName>.xcworkspace/xcshareddata/IDETemplateMacros.plist. Fifth, the User the Xcode data file path: ~ / Library/Developer/Xcode/UserData/IDETemplateMacros plist.Copy the code

The fifth can be viewed as a global configuration, where all Xcode projects under the same user use the idetemplatemacros.plist

By configuring different annotation templates, you can meet the need to use different annotations for personal and corporate projects or for other different projects.

The Text macros reference

Macros can be explained by referring to the Xcode FILEHEADER information FILEHEADER macros. Text Macros Reference-xcode Help, Text Macro format reference-xcode Help

Here is how some text macros look, macro name –> what is displayed

//
// COPYRIGHT --> COPYRIGHT © 2021 XXXXX. All rights reserved.
// DATE ---> 2021/5/20
/ / DEFAULTTOOLCHAINSWIFTVERSION - > 5.0
// FILEBASENAME ---> File
// FILEBASENAMEASIDENTIFIER ---> File
// FILENAME ---> File.swift
// FULLUSERNAME ---> XXXxxx
// NSHUMANREADABLECOPYRIGHTPLIST ---> 
      
       NSHumanReadableCopyright
      
<string>Copyright © 2021 xxxxx. All rights reserved. < /string>
// ORGANIZATIONNAME ---> xxxxx
// PACKAGENAME ---> Macros
// PACKAGENAMEASIDENTIFIER ---> Macros
// PRODUCTNAME ---> Macros
// PROJECTNAME ---> Macros
/ / RUNNINGMACOSVERSION - > 10.15
// TARGETNAME ---> Macros
// TIME ---> 09:41
// USERNAME ---> xxx
// UUID ---> 7E76936D-6461-41BE-8011-FCDEF050A7A3
// YEAR ---> 2021
Copy the code

NSHUMANREADABLECOPYRIGHTPLIST content have a newline, so there is no comment

More details can be found in the official documentation, some of which I reviewed in Resources.

The resources

Text macros reference – Xcode Help

Text macro format reference – Xcode Help

Customize text macros – Xcode Help

Customizing the file header comment and other text macros in Xcode 9

Xcode custom header file information in the project

Xcode FILEHEADER information FILEHEADER macros