Skip to content

Latest commit

 

History

History

Documentation

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

SwiftGen Documentation

This directory contains documentation for various topics related to SwiftGen, such as in-depth documentation about parsers and templates, but also articles with tips & tricks on how to best use SwiftGen in your workflow.

General Documentation

Integrating SwiftGen with other tooling

Creating your own templates

Customize loading of resources

Most of the SwiftGen provided templates generate code that allows you to load resources at runtime, but in some cases you may want to modify how these resources are loaded. The built-in templates can be configured to handle these cases without resorting to custom templates.

SwiftGen uses parsers to parse different type of input files, like asset catalogs, strings files, font files, etc.

You can find the documentation for each parser in Documentation/Parsers/, each describing the type of input file the parser supports, as well as the default file name filter it uses, and potential options that can be configured for that parser.

Each parser in SwiftGen (Assets Catalog parser, Strings parser, etc) comes with one or more built-in templates adapted to the type of input resources that parser will parse.
Each template can also accept parameters (params key in your swiftgen.yml config file) to adjust the generated code sligthly.

The documentation for each template, their intended use, and their supported parameters can be found in Documentation/templates/, organized in one subdirectory for each parser.

The way SwiftGen works is to parse your input files (resources like Asset Catalogs, Strings files, etc) using those parsers described above, and transform them into a structured dictionary – that we call a "SwiftGenKit Context" – representing the parsed data.

That parsed data ("Context") is then fed to our template engine (Stencil), alongside a template, to finally produce the generated code that you will use in your projects.

                                         +----------+
                                         | Template |
                                         +-----+----+
+---------------+        +-------------+       |      +------------+
| Resource file |        | SwiftGenKit |       v      | Generated  |
| (e.g. Assets) | -----> |   Context   | ------+----->| Swift code |
+---------------+        +-------------+              +------------+

\_ _ _ _ _ _ _ _ _ _ _ _ _ _ _/   \_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _/
     SwiftGenKit framework             Stencil Template Engine
\_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _/
                       SwiftGen Command Line

If you are writing your own templates, you will need to read the documentation about those SwiftGenKit Contexts – organized in subdirectories for each parser – to understand the variables that are produced and available in those contexts, for your custom templates to use.

Contexts are basically structured dictionaries and the documentation of contexts generated by each parser will tell you the structure and keys of those dictionaries that you can then use in your templates to use the parsed data.