Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. iOS
  3. Sourcery

Sourcery

MITSwift2.3.0

A Swift code generator that automates boilerplate code using meta-programming and SwiftSyntax.

Visit WebsiteGitHubGitHub
8.0k stars634 forks0 contributors

What is Sourcery?

Sourcery is a code generator for Swift that uses meta-programming to automate boilerplate code. It analyzes Swift source code and generates additional code based on customizable templates, solving the problem of writing repetitive, error-prone code for tasks like mocking, Equatable conformance, and Codable implementations.

Target Audience

Swift developers working on iOS, macOS, or Linux projects who need to reduce boilerplate code, improve code consistency, and automate repetitive coding patterns.

Value Proposition

Developers choose Sourcery because it dramatically reduces manual coding effort, ensures consistency across generated code, and integrates seamlessly with Swift projects through multiple installation methods including Swift Package Manager, CocoaPods, and Homebrew.

Overview

Meta-programming for Swift, stop writing boilerplate code.

Use Cases

Best For

  • Automatically generating mock implementations for Swift protocols in unit tests
  • Adding Equatable and Hashable conformance to complex Swift types
  • Implementing advanced Codable support for Swift enums and structs
  • Generating LinuxMain.swift files for Swift package manager projects
  • Creating lenses for immutable data structures in functional Swift
  • Automating UI generation for app settings or configuration screens

Not Ideal For

  • Teams requiring real-time code generation without separate build steps, as Sourcery must be run manually or integrated into the build process.
  • Projects with minimal boilerplate code where the overhead of setting up and maintaining Sourcery templates outweighs the benefits.
  • Environments with strict policies against generated code or external tool dependencies, due to code review or compliance requirements.

Pros & Cons

Pros

Massive Time Savings

Automatically generates hundreds of lines of mock code per protocol, as shown in the TL;DR example, drastically reducing manual effort for common tasks like AutoMockable.

Consistency and Accuracy

Ensures generated code like Equatable conformance is uniform and updates automatically with refactors, minimizing human error in boilerplate.

Flexible Template System

Supports Stencil templates for custom code generation, allowing automation of any describable algorithm beyond built-in use cases such as UI generation.

Proven Production Reliability

Used in over 40,000 projects including major apps like Airbnb and The New York Times, indicating robust community adoption and maintenance.

Cons

Steep Learning Curve

Creating custom templates requires proficiency in Stencil templating language and understanding of SwiftSyntax, which can be challenging for newcomers without prior experience.

Build-Time Overhead

Integration as a command-line tool or build phase adds complexity to the development workflow and can slow down build times, especially in large projects.

Swift-Exclusive Limitation

Only supports Swift, making it unsuitable for projects using multiple programming languages or needing cross-platform code generation tools.

Dependency on External Updates

Relies on stable SwiftSyntax, which might break with Swift compiler updates, requiring frequent maintenance and potential downtime for generated code.

Frequently Asked Questions

Quick Stats

Stars8,011
Forks634
Contributors0
Open Issues87
Last commit1 month ago
CreatedSince 2016

Tags

#ios#metaprogramming#boilerplate#codegenerator#mocking#testing#meta-programming#templates#swift#swiftsyntax#code-generation#automation#macos#codegen

Built With

S
Stencil
S
SwiftSyntax
S
Swift

Links & Resources

Website

Included in

iOS51.7kVapor1.3k
Auto-fetched 18 hours ago

Related Projects

inferinfer

A static analyzer for Java, C, C++, and Objective-C

Stars15,661
Forks2,098
Last commit1 day ago
R.swiftR.swift

Strong typed, autocompleted resources like images, fonts and segues in Swift projects

Stars9,569
Forks779
Last commit1 year ago
SwiftGenSwiftGen

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

Stars9,552
Forks765
Last commit3 months ago
XcodeGenXcodeGen

A Swift command line tool for generating your Xcode project

Stars8,642
Forks888
Last commit8 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub