Release Notes of SwiftGen

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

SwiftGen/SwiftGen

6.0.0

⚠️ 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.

added
  • 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.

changed
  • 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.

fixed
  • 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.

5.3.0
added
  • 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.

changed
5.2.1
fixed
  • 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).

5.2.0
added
  • 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.

fixed
  • 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 file.zip is not kept in Pods/SwiftGen/ anymore (freeing ~5MB on each install of SwiftGen made via CocoaPods!).

5.1.2
changed
  • 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.

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

5.1.0
added
  • 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.

5.0.0

⚠️ 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.

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

changed
  • 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
  • Improved installation instructions in the README.

4.2.1
added
  • Added the CONTRIBUTING.md file to help new contributors.

changed
fixed
  • 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.

4.2.0
added
  • 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 foo.bar=1 --param foo.baz=2).
    • You can then use them in your templates using e.g. {{param.tabs}}, {{param.foo.bar}} & {{param.foo.baz}}.
  • 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}}.
changed
  • 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.

4.1.0
added
  • 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.
changed
  • 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.

fixed
  • 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.

4.0.1
changed
  • 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.

fixed
  • 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.

4.0.0
added
  • 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.

changed
  • 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).

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

3.0.1
  • 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).
3.0.0
  • 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 foo.bar.baz) 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!
changed
  • 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.

2.0.0
  • 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.

1.1.2
  • Fix issue introduced by 1.1.1 in storyboard templates not returning.
1.1.1
  • Removed the last force-unwrap from storyboard templates.
1.1.0
  • 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.
1.0.0
  • 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.
0.8.0
  • 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.
0.7.6
fixed
  • 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 ~.

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

changed
  • 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
0.7.4
added
  • Added View Controller Placeholders support.

0.7.3
changed
  • 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>

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

changed
  • 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.

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

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

0.7.0
added
  • 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.

changed
  • 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.

fixed
  • Fix compilation issue for storyboards without any scene.

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

0.6.0
changed
  • 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.

fixed
  • Fix issue with .strings files encoded in UTF8.

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

0.5.1
changed
  • 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 Xcode.app (so it'll work on every machine even if you rename your Xcode).

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

0.5.0
added
  • 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.

fixed
  • Fix color parsing with absent alpha

0.4.4
  • Updated Unit tests for latest Swift 2.0 & tested against Xcode 7.1
  • Fix small typos in code
  • Guard against empty enums
0.4.3
  • Updated for Xcode 7 Beta 6.
0.4.2
  • Added import Foundation on top of swiftgen-l10n generated code.
0.4.1
  • 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.
0.4.0
  • 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)
0.3.0
  • 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.

0.2.0
  • Added Segues enums to UIStoryboard to be able to access their identifiers easily.
  • Added this very CHANGELOG.md
0.1.0

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
0.0.4
  • Introducing SwiftGenColorEnumBuilder
  • swiftgen-colors CLI
  • Added ability to choose indentation
0.0.3
  • Introducing SwiftGenL10nEnumBuilder
  • swiftgen-l10n CLI
  • Started playing with UIColor enums in the playground
0.0.2
  • Introducing SwiftGenStoryboardEnumBuilder class
  • swiftgen-storyboard CLI
0.0.1

Initial version:

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