A hands-on workshop of five Rust procedural macro projects, each with a skeleton and a trybuild test suite to implement.
krzysztofzablocki/Sourcery
A Swift code generator built on SwiftSyntax that uses templates to produce boilerplate such as mocks, Equatable, and Codable code.
- Stars
- 8,031
- Forks
- 634
- Open issues
- 95
- Last commit
- 9 days ago
What is it?
Sourcery is a command-line code generator for Swift. It parses your Swift source files with Apple's SwiftSyntax and feeds the resulting type information into Stencil templates, which then write out new Swift files. This removes repetitive code such as protocol mocks, equality and hashing implementations, enum case helpers, lenses, and Codable conformances.
A typical example is generating mocks: instead of hand-writing a mock class for each protocol, you add an annotation like `extension MyProtocol: AutoMockable {}` and Sourcery produces the mock. Because the output is regenerated from the source, mocks stay in sync when protocol members change.
Sourcery runs as a binary installed through Homebrew, CocoaPods, Mint, or Swift Package Manager, and it can also be used as a Swift package command plugin or a pre-commit hook. It supports a watch mode for regenerating code on file changes, and it provides a configuration file for sources, templates, and arguments.
Key features
- 01Generates protocol mocks with the AutoMockable annotation.
- 02Produces Equatable, Hashable, and Codable implementations from type definitions.
- 03Lets you write custom Stencil templates to automate arbitrary patterns.
- 04Offers a watch mode that regenerates code when sources or templates change.
- 05Installable via Homebrew, CocoaPods, Mint, SPM, or pre-commit.
Use cases
- Generating consistent mocks and stubs for all protocols in an iOS project.
- Keeping Equatable, Hashable, or Codable code in sync as model types change.
- Building project-specific code generation templates for repetitive architecture patterns.
- Automating settings screens or other UI code derived from type declarations.
Quick start
- 1
Install the sourcery binary with Homebrew
brew install sourcery - 2
Run sourcery with your sources, templates and output paths
./bin/sourcery --sources <sources path> --templates <templates path> --output <output path>
Things to know
- Templates written in JS are not supported when building with Swift Package Manager.
- The Xcode command plugin is only available from Xcode 14 onwards.
In collections
Topics
FAQ
- What is Sourcery?
- A Swift code generator built on SwiftSyntax that uses templates to produce boilerplate such as mocks, Equatable, and Codable code. Sourcery is a command-line code generator for Swift. It parses your Swift source files with Apple's SwiftSyntax and feeds the resulting type information into Stencil templates, which then write out new Swift files. This removes repetitive code such as protocol mocks, equality and hashing implementations, enum case helpers, lenses, and Codable conformances.
- Is Sourcery free to use? What license does it have?
- Sourcery is open source under the MIT license. Check the license terms before using it in commercial products.
- Is Sourcery still maintained?
- Actively maintained. The last commit to Sourcery was on Oct 28, 2026.
- What can I use Sourcery for?
- Generating consistent mocks and stubs for all protocols in an iOS project. Keeping Equatable, Hashable, or Codable code in sync as model types change. Building project-specific code generation templates for repetitive architecture patterns. Automating settings screens or other UI code derived from type declarations.
- How do I install Sourcery?
- Install the sourcery binary with Homebrew: brew install sourcery Run sourcery with your sources, templates and output paths: ./bin/sourcery --sources <sources path> --templates <templates path> --output <output path>
- Where can I get Sourcery?
- The source code and installation instructions are on GitHub: https://github.com/krzysztofzablocki/Sourcery
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A free, two-way Figma MCP server that lets coding agents turn Figma designs into code and write designs back to the canvas.
A Java library that plugs into editors and build tools to generate boilerplate such as getters, equals, builders and logging fields via annotations.
Boilerplate for building GenLayer intelligent contracts, using a football bets game as the example, with tests, linting, CI and a Next.js frontend.
A production-ready Next.js 15 starter template with TypeScript, Tailwind CSS v4, testing, linting and optional AWS deployment infrastructure.
A macOS app that gives a GUI for controlling iOS, tvOS, and watchOS simulators by wrapping Apple's simctl tool.