In a regular Xcode project app, when I right click to create a new file, it will offer me a template (eg. SwiftUI/Swift/Storyboard) to choose from. I choose a template, click on next, and the prompt will allow me to input the filename. After that, Xcode automatically generates the file with the filename given, the header filename, and the struct name in case of SwiftUI file.
However, in Swift Package Manager projects, right click to create new file don't give me the chance to input a filename and creates a default Swift or SwiftUI file with placeholder names like file.swift.
I solved this problem by using a custom file template. For more information on how to create a custom file template, please refer to xcode-project-and-file-templates. The template contains two files ___FILEBASENAME___.swift and TemplateInfo.plist.
___FILEBASENAME___.swift for the following.
//___FILEHEADER___
import Foundation
TemplateInfo.plist for the following.
<?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>An empty Swift file for package.</string>
<key>Summary</key>
<string>An empty Swift file for package.</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>
<key>Options</key>
<array>
<dict>
<key>Identifier</key>
<string>productName</string>
<key>Required</key>
<true/>
<key>Name</key>
<string>Name:</string>
<key>Description</key>
<string>The name of the file to create</string>
<key>Type</key>
<string>text</string>
<key>NotPersisted</key>
<true/>
</dict>
</array>
</dict>
</plist>