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 theoutput
parameter is now deprecated, in favour of theoutputs
parameter, and it may be removed in a future version of SwiftGen. Similarly, thepaths
parameter has been renamed toinputs
for consistency. You can always useswiftgen 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
andswiftgen 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
andyaml
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.
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 toib
, to better reflect it's purpose. An alias forstoryboards
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 oldnoAllValues
flag (with an inverse behaviour).XCAssets: Dropped the deprecated
allValues
constant, use the type specific constants such asallColors
,allDataItems
andallImages
. The default value ofimageAlias
has also been changed fromImage
toAssetImageTypeAlias
, 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
andNSPageController
correctly.Interface Builder: ensure the parser can handle files with and without "trait variations".
Restrict
SceneType
andInitialSceneType
to UIViewController when not targeting AppKit. When targeting AppKit, remove superfluousAny
.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.
Merged the
SwiftGenKit
andtemplates
repositories back into this repository for easier development and maintenance.
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 defaultconfig 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 allswiftlint:disable
exceptions in all templates.When installing SwiftGen via CocoaPods, the unneeded
file.zip
is not kept inPods/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 (seeswiftgen 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
#colorLiteral
s.
Useswiftgen 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.
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 toxcassets
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
CONTRIBUTING.md
file to help new contributors.
Update StencilGenKit to 1.0.2 and update Circle CI to Xcode 8.3.
Switch from Travis CI to Circle CI, clean up the Rakefile in the process.
Fix a bug in which the version of SwiftGen was reported as
v0.0
byswiftgen --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 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}}
.
- This command-line option can be repeated at will and used to pass structured custom parameters (e.g.
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}}
.
- 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.
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
ordot-syntax
(for Swift 2.3).Reworked the "dot-syntax" and "structured" templates to use the new
macro
andcall
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 theextraImports
template variable. Instead use the the newmodules
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 thefamilies
template variable.images
now supports multiple asset catalogs as input. Templates can now use thecatalogs
variable to access each individual catalog.storyboards
accepts multiple paths (to folders orstoryboard
files). All found storyboards will be available in thestoryboards
template variable.
Better error handling in the
colors
command.Stencil: added two new tags
macro
andcall
, 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
enum
s for namespacing instead ofstruct
s.
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
toAny
.Remove the
key
param label from thetr
function for Localized String in the Swift 3 template.The
swiftgen images
command now uses theactool
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 usingswiftgen 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 theRakefile
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 templatesswiftgen 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 likecolors
or a composed namecolors-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 asAny
— which is not aCVarArgType
. Now usingUnsafePointer<()>
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!
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 theswiftgen colors
subcommand. - Use
String(format:locale:arguments:)
and theNSLocale.currentLocale()
in the "string" templates so that it works with.stringdict
files and pluralization. - Add support for Android
colors.xml
files as input for theswiftgen 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 viarake
in a path containing~
.
Added support for
*.clr
files (files to storeNSColorList
'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
andstatic func
are prefixed withinstantiate…
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
- Now
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>
andStoryboardSegue.<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 thestring.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 onUIViewController
to accept aStoryboardSegue
as parameter.
You can now for example callvc.performSegue(UIStoryboard.Segue.Wizard.ShowPassword)
.SwiftGen now comes bundled with some alternate templates, especially
colors-rawValue
,images-allvalues
andstoryboards-lowercase
, in addition to the default templates.
Allow using custom templates by name.
- Now the
-t
flag expect a template name (defaults todefault
), and will search a matching template inApplication 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.
- Now the
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 astatic 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
orbrew install
will now copy the Swift dylibs too, so thatswiftgen
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 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
andswiftgen colors
. Seeswiftgen --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 ofswiftgen-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 invokesxcodebuild install
. You can now easily build & install allswiftgen-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 theUIColor
namespace - Changed the "namespacing
enum
" inUIStoryboard
to astruct
to avoid confusion with the inner enums - The
UIStoryboard.Scene
enums now usestatic func
instead ofstatic var
for the dedicatedViewController
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 toUIStoryboard
to be able to access their identifiers easily. - Added this very
CHANGELOG.md
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 outerenum
to avoid clobbering theUIStoryboard
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