Fixing the file header

First thing that happens when I create a Swift file is I get something that looks like this:

File Header

The file gets created with a comment that names the file and the project.   But if I’m using Xcode (or AppCode), and probably any other editor, the file name and project are in the title bar of the editor window.  In this example, R0Kit and Menu.   Including these as comments seems to be entirely superfluous.  The first few times, I manually delete these extra lines every time I create a file.  But the right thing to do is fix it so that these lines never get inserted in the first place.

I’m indebted to Keith Harrison for explaining how to do this (here: ).  The magic phrase is “Xcode text macro”.  In my case that means creating the file called ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist with the following content:

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “”&gt;

<plist version=”1.0″>



        <string>  Created by r0ml on ___DATE___

//  ___COPYRIGHT___</string>




And that’s it!

Well, almost.  Now when I create a Swift file, I get

// Created by r0ml on 4/16/18.
// Copyright © 2018 Semasiology. All rights reserved.

import Foundation

but what I really want is to import R0Kit.  Here’s my solution:

The definition of the file template is at 

/Applications/\ Templates/Source/Swift\ File.xctemplate

I don’t want to modify my Xcode bundle, because that will get over-written every tim I upgrade.   I can duplicate that template to my home directory, but then the sheet for selecting file types will list “Swift File” twice.  I don’t know how to change or remove the existing definition, but I can add a new one.  I copy the Xcode template to my home directory, renaming it to “R0Swift File”  (yes, R0 is my prefix).

ditto /Applications/\ Templates/Source/Swift\ File.xctemplate ~/Library/Developer/Xcode/Templates/File\ Templates/Source/R0Swift\ File.xctemplate

Then, edit the file named ___FILEBASENAME___.swift , replacing Foundation with R0Kit .  Now when I create a new file, I see

New File

and if I select R0Swift File, my file looks like 

// Created by r0ml on 4/16/18.
// Copyright © 2018 Semasiology. All rights reserved.

import R0Kit

And THAT’S it!