Last verified to work with Xcode 15.1.
Ten years later and I still find myself doing this on a new machine. I'd written a script and gist-ed it earlier to save myself time on new machines, but that script and gist got lost to the sands of time, so here's another one.
Open
~/Library/Developer/Xcode
Create a new folder
Templates/File Templates/My Templates
In a separate Finder window (tip: Cmd-N
does that), open (tip: Use Cmd-G
in
Finder to directly enter the path):
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/MultiPlatform/
Copy
Source/Swift File.xctemplate
User Interface/SwiftUI View.xctemplate
And paste them into My Templates
.
Edit them to your heart's content. I just wanted to remove
//___FILEHEADER___
from the ___FILEBASENAME___.swift
.
Now we'll see new entries in a new My Template
section that appears in the
new file picker in Xcode. All the way at the bottom. Great job Apple, I'm not
sure if all this effort was worth it (I could modify the original templates, but
there are all these security warnings and what not, and they'd get overwritten
on the next Xcode update anyways. Nothing has changed in 10 years, Xcode
continues to be the same pain).