By default, Xcode creates comments like this:
//
// AppDelegate.swift
// HeaderDemo
//
// Created by Cihat Gündüz on 09.05.19.
// Copyright © 2019 Jamit Labs GmbH. All rights reserved.
//
Much of the information is redundant (like the file name) or is inaccurate with the Git history providing more accurate info (contributors). Therefore it can be considered a best practices to use a header comment like this instead:
// Copyright © 2019 Jamit Labs GmbH. All rights reserved.
In order to move a project from the old format to the new one, you need to do two things:
- Use Search & Replace in Xcode to fix all existing headers in your project
- TEach Xcode how to create future files in your project using the new format
- Open your project in Xcode
- Open the Find navigator on the left pane (the magnifier icon)
- Choose "Replace" and "Regular Expression" as options
- Copy the following into the upper text field:
(?://[^\n]*\n)+// Created by[^\n]+\n// Copyright([^\n]+)\n//
- Click enter to start the search
- Copy the following into the lower text field:
// Copyright$1
- Click "Replace All" to replace all entries at once
- Open the root directory of your project in Finder
- Right-click your
xcodeproj
file and choose "Show package contents" - Create (if it doesn't exist already) and open the folder
xcshareddata
- Create (if it doesn't exist already) and open the file
IDETemplateMacros.plist
- Copy the following contents to the file and save it:
<?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> ___COPYRIGHT___</string>
</dict>
</plist>
Note that the FILEHEADER
keys string
value is what Xcode is using then creating a new file.
We're basically setting it to ___COPYRIGHT___
.