Website · Performance · Architecture rules
Scheme Generator is a Swift Package Manager command plugin that writes a shared Xcode scheme (.xcscheme) for every
product in your Package.swift, and removes the schemes of products that are gone. It is a great tool for a project
that is modularized or that uses TCA.
Add it to the dependencies of the package whose products need schemes:
.package(url: "https://github.com/mackoj/SchemeGeneratorPlugin.git", from: "0.5.8"),Requires Xcode 14 or later (swift-tools-version 5.7) on macOS 12 or later.
The plugin will display messages and errors in Xcode Report navigator.
If the schemesDirectory point to inside a workspace project.xcworkspace/xcshareddata/xcschemes you might need to restart Xcode to see all your schemes updated.
You can then invoke the plugin from the root of your repository like so:
swift package --allow-writing-to-package-directory scheme-generator
This will generate schemes for all compatible targets defined in your package and write them in schemesDirectory.
The --allow-writing-to-package-directory option is required: without it SwiftPM stops the plugin, since writing to the package directory without explicit permission is a sandbox violation.
You can pass --confFile newName.json to scheme-generator in order to change the default path for the configuration. It will be saved so that you will not be required to input the configuration fileName at each launch.
To use it you have to set a configuration file at the root of your project named schemeGenerator.json.
This file contains these keys:
schemesDirectory: A string that represents where the schemes will be saved(if you use TCA you can put it in workspace)removeNotGeneratedSchemes: A bool that represents if it should remove schemes that are no longer in Package.swiftoverwriteAlreadyGeneratedSchemes: A bool that represents if it should force the overwrite of schemes already present schemeexcludedSchemes: An array of String that represents the name of the schemes files that already exist and should never be removedverbose: A bool that represents if it should print more information in the console
{
"schemesDirectory": "Project/project.xcworkspace/xcshareddata/xcschemes",
"excludedSchemes": ["Target1Tests", "Target2Tests"],
"removeNotGeneratedSchemes": true,
"overwriteAlreadyGeneratedSchemes": false,
"verbose": true
}If a new configuration filename is used as explained in #basic-usage step 1. It will be saved so that you will not be required to input the configuration fileName at each launch.
You can use it in CI to automatically generate your schemes.
swift package --allow-writing-to-package-directory scheme-generator
It loads its configuration to figure out what it can do and where to apply it. Then it loads all the products from the Package.swift. Apply a filter to do just what is required then wrote the files in the schemesDirectory.
The scheme is based on a template. A run with an unchanged product list stops early (set overwriteAlreadyGeneratedSchemes to force it).
swift build --build-tests && swift testtests the plugin's pure core (Plugins/SchemeGeneratorPlugin/Core, shared with the test target through a symlink);scripts/smoke-test.shruns the plugin on a sample package.swift test --package-path Architecturechecks the architecture rules written with swift-llm-check; seeCODING_STANDARDS.md.swift package --package-path Benchmarks benchmarkruns the benchmarks; see docs/performance.md.


