Remove comments in the header of a project

Hi. I would like to definitely remove comments appearing in the header of a new Xcode project. How can I do so for my future projects, cause that would be annoying to select the header every time a new project is created and delete it. Thanks.

Accepted Reply

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:
<?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).

Replies

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:
<?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).

Thanks a lot.