skip to Main Content

When I create a new file in my project in the file header, I find this:

//
//  NameFile.swift
//  NameProject
//
//  Created by Name Surname on dd/mm/yy.
//

I would like to change it, but in the settings I don’t find where to do it.

I would like to change it for all possible future projects.

I would like to achieve such a thing.

//
//  NameFile.swift
//  NameProject
//
//

Edit:

I would like to try to remove the comment, but I can’t find solutions.

2

Answers


  1. Say you want to modify (or get rid of) the XCode Header comment.

    • First open XCode, Use File > New File… (⌘N) and choose Property List from the file templates.
    • Name it file IDETemplateMacros.plist
    • On the navigator, select the file as right-click Open as source code. Xcode will show us the property file as text. Property files are really just XML files.
    • Copy paste the following content:
    <!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>Created for ___PROJECTNAME___ in ___YEAR___
    // Using Swift ___DEFAULTTOOLCHAINSWIFTVERSION___</string>
    </dict>
    </plist>
    

    On the root dict we have added an entry with key FILEHEADER and a two-lines string as a value:

    Created for ___PROJECTNAME___ in ___YEAR___
    // Using Swift ___DEFAULTTOOLCHAINSWIFTVERSION___
    

    Save the file IDETemplateMacros.plist on the folder:

    ~/Library/Developer/Xcode/UserData/
    

    That’s it, now when creating a new project called MyProject the header will be:

    //Created for MyProject in 2022
    // Using Swift 5.0
    

    Note1. There is a list of macros on https://help.apple.com/xcode/mac/9.0/index.html?localePath=en.lproj#/dev7fe737ce0

    Note 2. As an example you can write:

     Created ___DATE___
    // ___COPYRIGHT___
    

    Note that there is a leading space but you do not include the // for the comment on the first line.

    Note 3. For a more list of options see:
    https://useyourloaf.com/blog/changing-xcode-header-comment/

    Login or Signup to reply.
  2. From https://developer.apple.com/forums/thread/711305?answerId=722311022#722311022

    Add ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist with an empty FILEHEADER entry to generate an empty comment.

    <?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></string>
    </dict>
    </plist>
    

    Xcode help:

    If you really want to remove that empty comment line then you will need to start adding custom file templates. eg for a No Comment Swift File template create the following:

    • ~/Library/Developer/Xcode/Templates/File Templates/MultiPlatform/Source/No Comment Swift File.xctemplate/___FILEBASENAME___.swift with import Foundation
      followed by an empty line
    • ~/Library/Developer/Xcode/Templates/File Templates/MultiPlatform/Source/No Comment Swift File.xctemplate/TemplateInfo.plist with something like

    TemplateInfo.plist

    <?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>SupportsSwiftPackage</key>
        <true/>
        <key>Kind</key>
        <string>Xcode.IDEFoundation.TextSubstitutionFileTemplateKind</string>
        <key>Description</key>
        <string>A no comment Swift file.</string>
        <key>Summary</key>
        <string>A no comment Swift file</string>
        <key>SortOrder</key>
        <string>1</string>
        <key>Image</key>
        <dict>
            <key>FileTypeIcon</key>
            <string>swift</string>
        </dict>
        <key>AllowedTypes</key>
        <array>
            <string>public.swift-source</string>
        </array>
        <key>Platforms</key>
        <array/>
        <key>DefaultCompletionName</key>
        <string>File</string>
        <key>MainTemplateFile</key>
        <string>___FILEBASENAME___.swift</string>
    </dict>
    </plist>
    

    The default empty Swift File template in the Xcode 14 beta is: /Applications/Xcode-beta.app/Contents/Developer/Library/Xcode/Templates/File Templates/MultiPlatform/Source/Swift File.xctemplate/ (do not edit this directly).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search