11

I want to change the default header in my Swift Package. Is this possible?

Note: I don't want to change it for a project. This is possible. If you want to change it for your Project: Changing the default header comment license in Xcode

Mischa
  • 15,816
  • 8
  • 59
  • 117
Godlike
  • 1,621
  • 2
  • 20
  • 33

1 Answers1

2

To change the header comment for a single Swift Package, you will have to put your IDETemplateMacros.plist file in the following location, relative to your package root :

.swiftpm/xcode/package.xcworkspace/xcshareddata/IDETemplateMacros.plist

Unfortunately, in Xcode 13, the package name macro won't work, but you can just specify it manually. Here's an example content for your macros file:

<?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>
//  ___FILENAME___
//  Your Package Name
// 
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright © 2021 Your Name Or Company. All rights reserved.
//</string>
</dict>
</plist>
Snowy_1803
  • 656
  • 2
  • 8
  • 24
  • This didn't work for me using Xcode 13. Note the path I tried was .swiftpm/xcode/xcshareddata/IDETemplateMacros.plist as package.xcworkspace didn't exist. – InsertWittyName Oct 22 '21 at 19:21
  • Create it then, I suppose. Xcode probably only creates the workspace automatically when you begin editing schemes – Snowy_1803 Oct 22 '21 at 22:03
  • @Snowy_1803 is there a way to auto generate the copyright year instead of hardcoding a specific year? – alobaili Mar 21 '22 at 06:55
  • 1
    @alobaili I suppose `___YEAR___` should work. The full list of Xcode text macros is available [here](https://help.apple.com/xcode/mac/9.0/index.html?localePath=en.lproj#/dev7fe737ce0), but some of them (such as `___COPYRIGHT___`) don’t work in swift packages – Snowy_1803 Mar 21 '22 at 07:52
  • Doesn't work for me. Also don't have a `package.xcworkspace` folder and creating it doesn't work either. – Mischa Jul 28 '22 at 12:23