Release Notes of SwiftGen

The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!



⚠️ This major version is a big milestone in which a lot of refactoring and cleaning has been done. Many features added over previous releases have been reworked and unified, while also preparing SwiftGen for future additions. This means that you'll need to adapt your configuration files (or command line invocations) and custom templates to work with this new major version.

Read the SwiftGen 6.0 Migration Guide for a list of changes you'll need to apply.

  • Add ability to list all custom fonts and register them using FontFamily.registerAllCustomFonts.

  • Add support for Swift Package Manager and Mint.

  • The swiftgen.yml config file now accepts multiple outputs for each command, allowing you to generate multiple outputs from the same files and content. This also means that the output parameter is now deprecated, in favour of the outputs parameter, and it may be removed in a future version of SwiftGen. Similarly, the paths parameter has been renamed to inputs for consistency. You can always use swiftgen config lint to validate your configuration file.

  • Use swiftlint:disable all in generated files to avoid interference with SwiftLint rules custom to the host project.

  • XCAssets: Added support for NSDataAssets.

  • Organised the generated code in sections for better readability, with all generated constants at the top of the file.

  • Added support for JSON, Plist and YAML files using the swiftgen json, swiftgen plist and swiftgen yaml commands. The parsed contexts and the generated files for each command have been kept quite similar, for easier switching between file formats.

  • Updated the playgrounds with the new json, plist and yaml commands, and updated the other pages to reflect the template changes.

  • We're deprecating the old --template CLI option in favor of --templateName, to better match the naming of the other options and the configuration file. The old --template option will remain until the next major version.

  • StencilSwiftKit 2.7.0

  • Stencil 0.13.1

  • Don't normalize string keys while parsing, let all transformation be done on template side. This makes the developer responsible to keep the language file organized, duplications won't be removed.

  • Remove Swift 2 support.

  • Renamed the storyboards command to ib, to better reflect it's purpose. An alias for storyboards still exists, but it will be removed at some point.

  • XCAssets: the generated templates won't namespace groups by default anymore, use the forceProvidesNamespaces flag to enable this behaviour again.

  • XCAssets: the templates won't generate any all-values accessors anymore by default. Use the allValues flag to enable this behaviour again. Note: this replaces the old noAllValues flag (with an inverse behaviour).

  • XCAssets: Dropped the deprecated allValues constant, use the type specific constants such as allColors, allDataItems and allImages. The default value of imageAlias has also been changed from Image to AssetImageTypeAlias, to be consistent with the other types.

  • Interface Builder: split up the storyboards template into 2 parts, one for scenes and one for segues.

  • Migrated to CircleCI 2.0.

  • Switched to using SwiftLint via CocoaPods instead of our own install scripts.

  • Enabled some extra SwiftLint rules for better code consistency.

  • Updated to latest Xcode (10.0.0) and Swift 4.2.

  • Update to Stencil 0.13.0, and use some of it's new filters in our templates.

  • Store testing contexts as YAML files instead of PLISTs.

  • Refactor the parsers as they're getting more complex.

  • Disabled a SwiftLint rule for function parameter count.

  • Fix memory leak in generated code for Fonts.

  • Interface Builder: ensure the templates handle GLKViewController, AVPlayerViewController and NSPageController correctly.

  • Interface Builder: ensure the parser can handle files with and without "trait variations".

  • Restrict SceneType and InitialSceneType to UIViewController when not targeting AppKit. When targeting AppKit, remove superfluous Any.

  • Fonts: disable a warning in generated font files for projects with conditional_returns_on_newlines SwiftLint rule enabled.

  • Interface Builder: the parser and templates now handle the "Inherit module from target" setting.

  • Strings: the parser now correctly handles formats such as % d and %#x.

  • Strings: ensure strings without arguments are not processed using String(format:).

  • Fix missing link in the README.

  • XCAssets: exposed getter for image name string.

  • XCAssets: exposed getter for color name string.

  • Allows to set all properties as public by using --param publicAccess on all templates.

  • Fix SwiftGen no longer working using CLI parameters (instead of config file).

  • Errors now properly exit with a non-zero exit code.

  • swiftgen --help prints the full help back again (and not just the help of the default config run subcommand).

  • You can now use a swiftgen.yml file to configure SwiftGen! 🎉
    Read more about it in the dedicated documentation.

  • Storyboards: Added a new ignoreTargetModule parameter if you're using storyboards in multiple targets, to avoid issues with the generated code.

  • Fixes an issue in High Sierra where the output of the processed Catalog Entries was not ordered alphabetically.

  • Fonts: fix code which checks if a font is already registered.

  • SwiftLint rules: Disabled the superfluous_disable_command rule for all swiftlint:disable exceptions in all templates.

  • When installing SwiftGen via CocoaPods, the unneeded is not kept in Pods/SwiftGen/ anymore (freeing ~5MB on each install of SwiftGen made via CocoaPods!).

  • Allows the SwiftGen source code to be built with Xcode 9. This also has the nice side-effect of making the homebrew installation of SwiftGen also available for macOS 10.13.

  • XCAssets: fixed some compatibility issues with the swift 3 template on Xcode 8, and with other templates.

  • Added Swift 4 templates. Use -t swift4 or whatever variant you want to use (see swiftgen templates list for the available names).

  • XCAssets: Added support for named colors. When using swiftgen xcassets the bundled templates will now also include colors found in the Asset Catalog in addition to the images.

  • Fonts: the path to fonts will now default to just the font filename, but you can disable this behaviour by enabling the preservePath parameter.

  • Colors: new template that uses #colorLiterals.
    Use swiftgen colors -t literals-swift3 / swiftgen colors -t literals-swift4 to use them.


⚠️ This major version is a big milestone in which a lot of refactoring and cleaning has been done. Many features added over previous releases have been reworked and unified, while also preparing SwiftGen for future additions. This means that you'll need to adapt your command line invocations and custom templates to work with this new major version.

Read the SwiftGen 5.0 Migration Guide for a list of changes you'll need to apply.

  • Colors and strings commands now accept multiple input files. With these 2 additions, all swiftgen generator commands are able to handle multiple input files.

  • SwiftGenKit 2.0.0

  • StencilSwiftKit 2.0.0

  • Stencil 0.9.0

  • templates 2.0.0

  • Removed deprecated CLI options. Please consult the migration guide should you still use them.

  • Disable default value for named template option and ensure that there is a template option.

  • Templates are now grouped by subcommand on the filesystem. This is only important if you had custom templates in the Application Support directory. To migrate your templates, place them in a subfolder with the name of the subcommand, and remove the prefix of the template filename.

  • The images command has been renamed to xcassets to better reflect its functionality.

  • Many deprecated templates have been removed (or merged), and others have been renamed to reflect new behaviours. Please check the templates migration guide for more information.

  • There have been some breaking changes in the generated code for storyboards. Please check the templates migration guide for more information, where we also provide a compatibility template.

  • Removed deprecated template context variables, and restructured many others. Please check the SwiftGenKit migration guide for more information.

  • Some filters have been removed in favour of Stencil's built in versions, and other filters have been updated to accept parameters. Please consult the StencilSwiftKit migration guide for more information.

  • Switch back from actool to an internal parser to fix numerous issues with the former. This fixes issues a few people encountered when using asset catalogs that contained some of the less common set types.

  • Improved installation instructions in the README.

  • Added the file to help new contributors.

  • Fix a bug in which the version of SwiftGen was reported as v0.0 by swiftgen --version.

  • Fix remaining enum names not Swift 3 compliant.

  • You can now pass custom parameters to your templates using the --param X=Y syntax.

    • This command-line option can be repeated at will and used to pass structured custom parameters (e.g. --param tabs=2 --param --param foo.baz=2).
    • You can then use them in your templates using e.g. {{param.tabs}}, {{}} & {{}}.
  • Templates can now access environment variables via the env key of the Stencil context (e.g. {{env.USER}}, {{env.LANG}}).

    • This is especially useful when integrating SwiftGen as a Script Build Phase in your Xcode project as you can then access Xcode Build Settings exposed as environment variables by Xcode, e.g. {{env.PRODUCT_MODULE_NAME}}.
  • SwiftGenKit 1.0.1

  • StencilSwiftKit 1.0.0

  • Stencil 0.8.0

  • templates 1.0.0

  • Use an explicit bundle parameter to support frameworks for all templates.

  • In preparation for an upcoming cleanup of SwiftGen to remove some legacy code as well as Stencil old variables, tags and filters, and change the default templates to Swift 3, some things are being deprecated and will be removed in the next major version 5.0.

    As a result, if you wrote custom templates, you should already prepare for the upcoming 5.0 by migrating your templates to use the new variables (already avaiable in SwiftGen 4.2 / SwiftGenKit 1.0).

    See #244 and the Migration Guide for a list of deprecations and their replacements.

  • Storyboards templates won't import your app module anymore, removing that annoying warning.

  • SwiftGen has migrated to its own GitHub organization 🎉.

  • SwiftGen has been split in multiple repositories and separate modules.

    • The present SwiftGen is the CLI parsing. It is in charge of calling the frameworks, feeding them appropriate parameters according to the command line arguments.
    • SwiftGenKit is the framework responsible for parsing your assets/resources and turning them into a structured representation compatible with Stencil templates.
    • StencilSwiftKit is a framework adding some extensions to the template engine Stencil used by SwiftGen. It adds some tags and filters as well as convenience methods shared both by SwiftGen itself and by Sourcery.
    • The SwiftGen templates has been moved into a dedicated templates repo so they can evolve and be unit-tested separately of SwiftGen.

    Note: The next minor version will focus on bringing more documentation for all this new structure and improve ease of future contributions.

  • Added a script reference to simplify and automate localization of existing non localized project.

  • Added a storyboards-osx-swift3 template.

  • Added a strings-no-comments-swift3 template that does not include the default translation of each key.

  • Images: new dot-syntax template, use dot-syntax-swift3 or dot-syntax (for Swift 2.3).

  • Reworked the "dot-syntax" and "structured" templates to use the new macro and call tags, which greatly simplifies the templates, and also removes the limitation of 5-level deep structures.

  • Storyboards: automatically detect the correct modules that need to be imported. The --import option has therefore been deprecated, as well as the extraImports template variable. Instead use the the new modules variable, which offers the same functionality.

  • Support multiple input paths for some commands:

    • fonts accepts multiple input directories, all found fonts will be added to the families template variable.
    • images now supports multiple asset catalogs as input. Templates can now use the catalogs variable to access each individual catalog.
    • storyboards accepts multiple paths (to folders or storyboard files). All found storyboards will be available in the storyboards template variable.
  • Better error handling in the colors command.

  • Stencil: added two new tags macro and call, see the to use them.

  • SwiftLint: Remove switch_case_on_newline warning for generated color file.

  • Stencil: better string filter testing and fixed a small issue with lowerFirstWord.

  • Strings: fix issue with dot-syntax-swift3 where function definitions were not Swift 3 guidelines compliant.

  • Snake cased keys with uppercase letters are correctly camel cased again.

  • Swift 3 migration.

  • Restructure the SwiftGen project to build as an .app during developement, for easier debugging in Xcode.

  • Consolidate the use of PathKit internally.

  • Updated Stencil to 0.7.2.

  • Escape newlines again in .strings file keys.

  • Fix broken import option added in 4.0.0.

  • Show an error when the provided path to the images command is not an asset catalog.

  • Strings dot-syntax template: use enums for namespacing instead of structs.

  • Add support for multiline strings in *.strings file.

  • Add option to add import statements at the top of the generated swift file (for storyboards) using the import flag.

  • Escape reserved swift keywords in the structured and dot-syntax generated strings code.

  • Change swift 3 storyboard segue template's sender from AnyObject to Any.

  • Remove the key param label from the tr function for Localized String in the Swift 3 template.

  • The swiftgen images command now uses the actool utility to parse asset catalogs, ensuring that the parser correctly handles namespaced folders.
    ⚠️ Note that you now have to specify the exact path to your .xcassets assets catalogs when using swiftgen images (and not just a directory to parse).

  • Fix swift 3 storyboard templates to be compliant with swift 3 api design guidelines.

  • Add support for Xcode 8 and Swift 2.3.
    (Should still compile in Xcode 7.3 but the Rakefile to build, install and release requires Xcode 8).
  • Add template that calls NSLocalizedString() separately for each string, which is useful when trying to extract strings in the app to a .strings file.
  • Add some file_length and similar SwiftLint exceptions in bundled templates, as files generated by SwiftGen might contain lots of constants and can be long by design.
  • Error messages ("template not found", etc) are now printed on stderr.
  • Add more swiftgen templates subcommands.
    • swiftgen templates list lists all the available templates
    • swiftgen templates which <name> prints the path to the template named <name>
    • swiftgen templates cat <name> prints the content to the template named <name>
    • <name> here can be either a subcommand name like colors or a composed name colors-rawValue for a specific template.
  • Fix swift 3 renaming change in strings-swift3.stencil.
  • Fix non-custom class, non-base view controller handling in storyboards-swift3.stencil.
  • Add strongly typed initialViewController() overrides for storyboard templates if available.
  • Add support for font files containing multiple descriptors.
  • Update deprecated usage of generics for Swift 3 / Xcode 8 beta 6.
  • Fix case when missing positional parameters, which leads to parameters in the enum with unspecified type (undeterminable from the Localizable.strings format analysis) where reported as Any — which is not a CVarArgType. Now using UnsafePointer<()> arguments instead for such odd edge-cases that should never happen anyway.
  • Now reports an error when it failed to parse a color in a color input file.
  • New Strings template (available via -t dot-syntax), allowing string keys containing dots (like to be organized as a hierarchy and accessible via dot syntax.
  • Update Swift 3 templates to use lowercase enums.
  • New Strings template (available via -t dot-syntax-swift3), allowing keys with dots in Swift 3 (see above).

💡 You can now create your custom templates more easier than ever, by cloning an existing template!

e.g. to clone the default strings-default.stencil template:

  • use swiftgen templates cat strings --output strings-custom.stencil
  • modify the cloned strings-custom.stencil template to your liking
  • use it with swiftgen strings … --templatePath strings-custom.stencil … in your projects!
  • Some keys for various templates have changed to provide more flexibility and enable some new features in the templates. As a result, if you created your own custom templates, they might not all be totally compatible with SwiftGen 3.0.0 (hence the new major version). Please read the Custom Templates documentation to find out the new Stencil context keys and update your custom templates accordingly.

    If you're using one of the bundled templates, all of them have been updated appropriately.

  • Also if you use Swift 3, and thus use the -t swift3 flag to use the Swift 3 templates, be advised those has been modified to take the latest Swift 3 modifications into account (including naming convensions) so your code might need to be updated according to match the latest Swift 3 recommendations.

  • Fix issue with txt files bailing on comments.
  • Added support for tvOS and watchOS in images, fonts and color templates.
  • Added enum-based structured identifiers via -t structured option.
  • Added support for OSX in storyboards.

Note: The Stencil context keys (the name of the variables used in templates) for storyboard has changed a bit. Especially, class has been renamed into customClass (see #131) to better describe the intent (as this isn't defined if there is no custom class set in the Storyboard), and new keys isBaseViewController and baseType has been added.

This means that if you did implement your own custom templates for storyboards (instead of using the bundled ones), you'll have to remplace {{class}} by {{customClass}} in those storyboard templates, otherwise they'll probably stop working as expected. That's the main reason why the version has been bumped to a major version 2.0.0.

  • Fix issue introduced by 1.1.1 in storyboard templates not returning.
  • Removed the last force-unwrap from storyboard templates.
  • Added step to ensure all templates are Swiftlint'ed and don't violate any code style rule.
  • Added support for OSX in images, fonts and color templates.
  • Added missing FontConvertible protocol conformance to default fonts template.
  • Restructured colors & fonts templates to workaround the same LLVM issue as #112 with nested types inside existing UIKit classes in Release/Optimized builds.
  • Added support for Fonts using the swiftgen fonts command.
  • Added support for TXT (colors.txt) files to have named value.
  • Restructured image templates to work around an LLVM issue with nested types.
  • Added Swift 3 templates for storyboards and strings.
  • Introducing alternative way to install SwiftGen: using CocoaPods! See README for more details.
  • Added support for JSON (colors.json) files as input for the swiftgen colors subcommand.
  • Use String(format:locale:arguments:) and the NSLocale.currentLocale() in the "string" templates so that it works with .stringdict files and pluralization.
  • Add support for Android colors.xml files as input for the swiftgen colors subcommand.
  • Removed the useless import Foundation from the "images" templates.
  • Added computed property var color: UIColor to the color templates.
  • Fixed build loop by changing SwiftGen to only write to the output file if the generated code is different from the file contents.

  • Fixed typos in code and descriptions: instanciate -> instantiate. Please note that the default template used for storyboards storyboards-default.stencil had to be modified, so make sure to update your codebase accordingly.

  • Fixed issue in Rakefile when trying to install via rake in a path containing ~.

  • Added support for *.clr files (files to store NSColorList's presented in Color Picker on "Color Palettes" tab).

  • Updated stencils and unit tests to pass SwiftLint.

  • Updated storyboards-default.stencil to better avoid name confusions.

    • Now cases names are suffixed with …Scene and static func are prefixed with instantiate… to lower the risks of a name conflict with your ViewController classes.
    • The old template is still available but has been renamed storyboards-uppercase.stencil
  • Added View Controller Placeholders support.

  • Restructured storyboard templates to work around an LLVM issue with nested types.

    Scenes and Segues are now referenced via StoryboardScene.<Storyboard> and StoryboardSegue.<Storyboard>.<Segue>

  • Adding comments to generated color enums which allow you to see the color in the QuickHelp documentation

  • The default translation of strings are now added as documentation comments to the enum cases.
    You can add translations to your own templates by using the string.translation variable.

  • Fix an issue with the colors template due to an Apple Bug when building in Release and with WMO enabled.

  • Fix issue with swiftgen strings that were using the colors templates instead of the strings template by default.

  • Add a performSegue(_:sender:) extension on UIViewController to accept a StoryboardSegue as parameter.
    You can now for example call vc.performSegue(UIStoryboard.Segue.Wizard.ShowPassword).

    SwiftGen now comes bundled with some alternate templates, especially colors-rawValue, images-allvalues and storyboards-lowercase, in addition to the default templates.

  • Allow using custom templates by name.

    • Now the -t flag expect a template name (defaults to default), and will search a matching template in Application Support first, then in the templates bundled with SwiftGen.
    • You can still specify a template by path using -p.
    • For more info, see this dedicated documentation.
  • You can now list all templates available (both bundled templates and custom ones) using the swiftgen templates command.

  • Now swiftgen storyboards doesn't generate duplicate enum cases for identical segues (those having equal identifiers and shared custom class).

  • Propose an alternate template using lowercase names, especially for when storyboard identifiers match view controller class names.

  • Introduced an image-allvalues template that exposes the list of all images in a static let allValues array.

  • Fix compilation issue for storyboards without any scene.

  • Fix issue with Storyboards without any StoryboardID (all scenes being anonymous) not extending StoryboardScene.

  • SwiftGen now uses Stencil template engine to produce the generated code.

  • This means that the generate code will be easier to improve

  • This also means that you can use your own templates to generate code that better suits your needs and preferences, using swiftgen … --template FILE …

  • The correct type of ViewController (UIViewController, UINavigationController, UITableViewController, …) is now correctly generated even if not a custom subclass.

  • Fix issue with .strings files encoded in UTF8.

  • It's now possible to specify which chars should not be used when generating case identifiers.

  • Installing via rake install or brew install will now copy the Swift dylibs too, so that swiftgen installation won't depend on the location of your (so it'll work on every machine even if you rename your Xcode).

  • Fixed links in Playground and Licence headers in source code.

  • Migrating to Commander to parse the CLI arguments.

  • swiftgen is now a single binary, and the subcommand names have changed to be more consistent.

  • New --output option.

    You must now use the subcommands swiftgen images, swiftgen strings, swiftgen storyboards and swiftgen colors. See swiftgen --help for more usage info.

  • Fix color parsing with absent alpha

  • Updated Unit tests for latest Swift 2.0 & tested against Xcode 7.1
  • Fix small typos in code
  • Guard against empty enums
  • Updated for Xcode 7 Beta 6.
  • Added import Foundation on top of swiftgen-l10n generated code.
  • Updated for Xcode 7 Beta 5
  • swiftgen-storyboard now allows to take a path to a .storyboard file as argument (as an alternative to give a path to a whole directory)
  • The -v and --version flags are now recognized and print the executable version.
  • Reorganized files into an Xcode project with one target per executable.
  • Added Unit Tests (one per executable + one for common code).
  • Improved SwiftGen-L10n parsing of format strings and placeholders.
  • Updated Rakefile so that it now invokes xcodebuild install. You can now easily build & install all swiftgen-xxx executables in /usr/local/bin or anywhere else.
  • Added a version string (date + sha1) to the built executables (displayed when invoked with no argument)
  • Reducted the default code generated by SwiftGenColorEnumBuilder to avoid clobbering the UIColor namespace
  • Changed the "namespacing enum" in UIStoryboard to a struct to avoid confusion with the inner enums
  • The UIStoryboard.Scene enums now use static func instead of static var for the dedicated ViewController constructors ^(†)

^(†) because it feels more explicit that calling a function like UIStoryboard.Scene.Wizard.validatePasswordViewController() will actually instantiate a new ViewController, rather than returning an existing one.

  • Added Segues enums to UIStoryboard to be able to access their identifiers easily.
  • Added this very

Considered to be the first cleaned-up version, far from finished but really usable with clean code.

  • Cleaner README
  • Namespace the generated enums in an outer enum to avoid clobbering the UIStoryboard namespace
  • Introducing SwiftGenColorEnumBuilder
  • swiftgen-colors CLI
  • Added ability to choose indentation
  • Introducing SwiftGenL10nEnumBuilder
  • swiftgen-l10n CLI
  • Started playing with UIColor enums in the playground
  • Introducing SwiftGenStoryboardEnumBuilder class
  • swiftgen-storyboard CLI

Initial version:

  • Mostly testing stuff in a playground
  • Introducing SwiftGenAssetsEnumBuilder class
  • swiftgen-assets CLI