A Swift Package Manager build tool plugin that generates type-safe Swift symbols from .xcstrings String Catalog files. Think of it as STRING_CATALOG_GENERATE_SYMBOLS for SPM
Starting with Xcode 26, you can enable STRING_CATALOG_GENERATE_SYMBOLS to automatically generate type-safe symbols from your String Catalogs. This lets you reference localized strings using compile-time checked symbols instead of error-prone string literals:
// Instead of this:
Text("welcome_message")
// You can write this:
Text(.welcomeMessage)However, this feature only works when building from Xcode - it doesn't work with swift build or swift test from the command line.
XCStringsPlugin bridges this gap. It uses the same xcstringstool that Xcode uses under the hood, allowing your SPM packages to build with type-safe string symbols from both Xcode and the command line.
- macOS with Xcode 26 or later installed
- Swift 6.2 or later
Add the plugin as a dependency in your Package.swift:
dependencies: [
.package(url: "https://github.com/sveinhal/XCStringsPlugin.git", from: "1.0.0")
]Then apply the plugin to your target(s):
targets: [
.target(
name: "MyLibrary",
plugins: [
.plugin(name: "GenerateSymbols", package: "XCStringsPlugin")
]
)
]When building from Xcode, the plugin does nothing, and expects Xcode's built-in symbol generation to do the job. Make sure you have enabled the build setting:
STRING_CATALOG_GENERATE_SYMBOLS = YES
You can set this in your Xcode project's Build Settings, or add it to an .xcconfig file.
The plugin detects .xcstrings files in your target and generates corresponding Swift symbol files:
- When building with
swift build: The plugin runsxcstringstool generate-symbolsto create Swift files with type-safe accessors. - When building from Xcode: The plugin returns no commands, and thus does nothing, allowing Xcode's native
STRING_CATALOG_GENERATE_SYMBOLSmechanism to handle generation instead.
This dual approach prevents conflicts (duplicate symbol definitions) while ensuring your package builds correctly in both environments.
Given a Localizable.xcstrings file with these keys:
{
"welcome_message": { "localizations": { "en": { "stringUnit": { "value": "Welcome!" } } } },
"item_count %lld": { "localizations": { "en": { "stringUnit": { "value": "%lld items" } } } }
}You can use the generated symbols in your code:
import SwiftUI
struct ContentView: View {
let count: Int
var body: some View {
VStack {
Text(.welcomeMessage)
Text(.itemCount(count))
}
}
}- macOS only: The plugin requires
xcrunto locatexcstringstool, which is only available on macOS with Xcode installed. - Xcode 26+: The
xcstringstoolwithgenerate-symbolssupport is only available in Xcode 26 and later.
MIT License. See LICENSE for details.