SwiftGen /SwiftGen

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

★ 9,543⑂ 761👁 100⑃ 490● 621▤ 44
SwiftMITCreated 2015-07-15
下载:6.6.36.6.3 ↓6.6.32024-03-02
+0
日增长
9,543
stars
761
forks
100
watchers
490
prs
621
issues
44
releases

README

SwiftGen



!Swift 4.x !Swift 5.x

SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them type-safe to use.


  
    
  
    
        Installation
        Configuration File
        Choosing your template
        Additional documentation
    
    Then generate constants for:
    
      Assets Catalogs
      Colors
      Core Data
      Files
      Fonts
      Interface Builder files
      JSON and YAML files
      Plists
      Localizable strings
    
  




There are multiple benefits in using this:

 Avoid any risk of typo when using a String
 Free auto-completion
 Avoid the risk of using a non-existing asset name
 All this will be ensured by the compiler and thus avoid the risk of crashing at runtime.

Also, it's fully customizable thanks to Stencil templates, so even if it comes with predefined templates, you can make your own to generate whatever code fits your needs and your guidelines!

 Installation

There are multiple possibilities to install SwiftGen on your machine or in your project, depending on your preferences and needs:


Download the ZIP for the latest release

 Go to the GitHub page for the latest release
 Download the swiftgen-x.y.z.zip file associated with that release
 Extract the content of the zip archive in your project directory

We recommend that you unarchive the ZIP inside your project directory and commit its content to git. This way, all coworkers will use the same version of SwiftGen for this project.

If you unarchived the ZIP file in a folder e.g. called swiftgen at the root of your project directory, you can then invoke SwiftGen in your Script Build Phase using:

sh
"${PROJECT_DIR}/swiftgen/bin/swiftgen" …


---


Via CocoaPods

If you're using CocoaPods, simply add pod 'SwiftGen', '~ 6.0' to your Podfile.

Then execute pod install --repo-update (or pod update SwiftGen if you want to update an existing SwiftGen installation) to download and install the SwiftGen binaries and dependencies in Pods/SwiftGen/bin/swiftgen next to your project.

Given that you can specify an exact version for SwiftGen in your Podfile, this allows you to ensure all coworkers will use the same version of SwiftGen for this project.

You can then invoke SwiftGen in your Script Build Phase using:

sh
if [[ -f "${PODS_ROOT}/SwiftGen/bin/swiftgen" ]]; then
  "${PODS_ROOT}/SwiftGen/bin/swiftgen" …
else
  echo "warning: SwiftGen is not installed. Run 'pod install --repo-update' to install it."
fi


 Similarly, be sure to use Pods/SwiftGen/bin/swiftgen instead of just swiftgen where we mention commands with swiftgen in the rest of the documentation.

_Note: SwiftGen isn't really a pod, as it's not a library your code will depend on at runtime; so the installation via CocoaPods is just a trick that installs the SwiftGen binaries in the Pods/ folder, but you won't see any swift files in the Pods/SwiftGen group in your Xcode's Pods.xcodeproj. That's normal; the Swift

Top issues

Discussions

Latest release

6.6.3 6.6.3 2024-03-02
Breaking Changes

_None_

 New Features

 CLI: Added support for --quiet and --verbose flags to swiftgen run.  
  John Szumski
  1007
  1008

 Bug Fixes

 Build: Fixed the rake cli:install command and with it the Homebrew formula.  
  Liquidsoul
  1030
  1104
  1105

 Internal Changes

_None_

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON