Supercharge Swift with SwiftGen

The Swift code generation tool for colors, images, strings & more!

let image = Image("my-cool-image") // Stop doing this 😡
// swiftgen.ymlxcassets:
- YourProjectName/Assets.xcassets // 1
templateName: swift5 // 2
output: ProjectName/Assets.swift // 3
  1. The template you are using, run swiftgen template list to try them out.
  2. The output file name for the generated code.
generated swift code, ty swiftgen!
let image = Image(Asset.myCoolImage) // Do this 😎
// swiftgen.ymlstrings:
inputs: TemplateProject/Localizable.strings // 1
- templateName: structured-swift5
output: TemplateProject/Generated/Strings.swift
var body: some View {
Text(L10n.Onboarding.Buttons.join) // 🎉

⚠️ You can also concatenate Strings if they are dynamic using %@ in the Localizable.strings file.

The last thing I want to show about SwiftGen is that you can create your own code generation templates to achieve various tedious tasks. Here’s an example of that, this template generates colors and images compatible with SwiftUI (credit to sebj on GH for the template idea).

- YourProjectName/Assets.xcassets
templatePath: xcassets-swiftui.stencil // 1
output: ProjectName/Assets.swift
var body: some View {
.cornerRadius(10) // this compiles
🔊 audio narration

Shameless plug: if you enjoyed this check my Patreon or YouTube for tutorials and posts I make around Swift and swe’ing in general 😎

iOS Software Engineer ⚡️ Creator