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:
inputs:
- YourProjectName/Assets.xcassets // 1
outputs:
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
outputs:
- 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).

xcassets:
inputs:
- YourProjectName/Assets.xcassets
outputs:
templatePath: xcassets-swiftui.stencil // 1
output: ProjectName/Assets.swift
var body: some View {
Asset
.myCoolImage
.image
.resizable()
.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