Need help with Sourcery?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

6.2K Stars 467 Forks MIT License 1.1K Commits 46 Opened issues


Meta-programming for Swift, stop writing boilerplate code.

Services available


Need anything else?

Contributors list

CircleCI <!-- codecov --> docs Version License Platform

There is now a new powerful way to both write and integrate Sourcery functionality: Sourcery Pro provides powerful Stencil editor and extends Xcode with ability to handle live AST templates: available on Mac App Store

Learn more about Sourcery Pro

Sourcery is a code generator for Swift language, built on top of Apple's own SwiftSyntax. It extends the language abstractions to allow you to generate boilerplate code automatically.

It's used in over 40,000 projects on both iOS and macOS and it powers some of the most popular and critically-acclaimed apps you have used (including Airbnb, Bumble, New York Times). Its massive community adoption was one of the factors that pushed Apple to implement derived Equality and automatic Codable conformance. Sourcery is maintained by a growing community of contributors.

Try Sourcery for your next project or add it to an existing one -- you'll save a lot of time and be happy you did!


Sourcery allows you to get rid of repetitive code and create better architecture and developer workflows. An example might be implementing

for all your protocols, without Sourcery you will need to write hundreds lines of code per each protocol like this:
class MyProtocolMock: MyProtocol {

//MARK: - sayHelloWith
var sayHelloWithNameCallsCount = 0
var sayHelloWithNameCalled: Bool {
    return sayHelloWithNameCallsCount &gt; 0
var sayHelloWithNameReceivedName: String?
var sayHelloWithNameReceivedInvocations: [String] = []
var sayHelloWithNameClosure: ((String) -&gt; Void)?

func sayHelloWith(name: String) {
    sayHelloWithNameCallsCount += 1
    sayHelloWithNameReceivedName = name


and with Sourcery ?

extension MyProtocol: AutoMockable {}

Sourcery removes the need to write any of the mocks code, how many protocol do you have in your project? Imagine how much time you'll save, using Sourcery will also make every single mock consistent and if you refactor or add properties, the mock code will be automatically updated for you, eliminating possible human errors.

Sourcery can be applied to arbitrary problems across your codebase, if you can describe an algorithm to another human, you can automate it using Sourcery.

Most common uses are:

But how about more specific use-cases, like automatically generating all the UI for your app

? you can use Sourcery for that too

Once you start writing your own template and learn the power of Sourcery you won't be able to live without it.

How To Get Started

There are plenty of tutorials for different uses of Sourcery, and you can always ask for help in our Swift Forum Category.


  • Binary form

    Download the latest release with the prebuilt binary from release tab. Unzip the archive into the desired destination and run

  • Homebrew

    brew install sourcery
  • CocoaPods


    pod 'Sourcery'
    to your
    and run
    pod update Sourcery
    . This will download the latest release binary and will put it in your project's CocoaPods path so you will run it with

    If you only want to install the

    binary and its
    dependency, you may want to use the
    pod 'Sourcery', :subspecs => ['CLI-Only']
  • Mint

    Mint is no longer recommended, due to how SwiftSyntax dylib linking and lack of SPM support for changing r-path, you can't just build sourcery with plain SPM and expect it to work with different Xcode versions across your team.

  • Building from source

    Download the latest release source code from the release tab or clone the repository and build Sourcery manually.

    • Building with Swift Package Manager


      swift build -c release
      in the root folder. This will create a
      folder and will put the binary there. Move the whole
      to your desired destination and run with

      Note: JS templates are not supported when building with SPM yet.

    • Building with Xcode

      Generate xcodeproj with

      swift package generate-xcodeproj


      and build with
      scheme. This will create
      in the Derived Data folder. You can copy it to your desired destination and run with


Full documentation for the latest release is available here.


Sourcery is a command line tool; you can either run it manually or in a custom build phase using the following command:

$ ./bin/sourcery --sources  --templates  --output 

Note: this command differs depending on how you installed Sourcery (see Installing)

Command line options

  • --sources
    - Path to a source swift files or directories. You can provide multiple paths using multiple
  • --templates
    - Path to templates. File or Directory. You can provide multiple paths using multiple
  • --force-parse
    - File extensions of Sourcery generated file you want to parse. You can provide multiple extension using multiple
    options. (i.e.
    will be parsed even if generated by Sourcery if
    --force-parse toparse
    ). Useful when trying to implement a multiple phases generation.
    can also be used to process within a sourcery annotation. For example to process code within
    annotation you can use
    --force-parse AutoCodable
  • --output
    [default: current path] - Path to output. File or Directory.
  • --config
    [default: current path] - Path to config file. File or Directory. See Configuration file.
  • --args
    - Additional arguments to pass to templates. Each argument can have an explicit value or will have implicit
    value. Arguments should be separated with
    without spaces (i.e.
    --args arg1=value,arg2
    ). Arguments are accessible in templates via
  • --watch
    [default: false] - Watch both code and template folders for changes and regenerate automatically.
  • --verbose
    [default: false] - Turn on verbose logging
  • --quiet
    [default: false] - Turn off any logging, only emit errors
  • --disableCache
    [default: false] - Turn off caching of parsed data
  • --prune
    [default: false] - Prune empty generated files
  • --version
    - Display the current version of Sourcery
  • --help
    - Display help information

Configuration file

Instead of CLI arguments you can use a

configuration file:

Read more about this configuration file here.


If you get unverified developer warning when using binary zip distribution try:

xattr -dr Sourcery-1.1.1


Contributions to Sourcery are welcomed and encouraged!

It is easy to get involved. Please see the Contributing guide for more details.

A list of contributors is available through GitHub.

To clarify what is expected of our community, Sourcery has adopted the code of conduct defined by the Contributor Covenant. This document is used across many open source communities, and articulates my values well. For more, see the Code of Conduct.


If you'd like to support Sourcery development you can do so through GitHub Sponsors or Open Collective, it's highly appreciated 🙇‍


Sourcery is available under the MIT license. See LICENSE for more information.


This tool is powered by

Thank you! to:

  • Mariusz Ostrowski for creating the logo.
  • Artsy Eidolon team, because we use their codebase as a stub data for performance testing the parser.
  • Olivier Halligon for showing me his setup scripts for CLI tools which are powering our rakefile.
  • JP Simard for creating SourceKitten that originally powered Sourcery and was instrumental in making this project happen.

Other Libraries / Tools

If you want to generate code for asset related data like .xib, .storyboards etc. use SwiftGen. SwiftGen and Sourcery are complementary tools.

Make sure to check my other libraries and tools, especially: - KZPlayground - Powerful playgrounds for Swift and Objective-C - KZFileWatchers - Daemon for observing local and remote file changes, used for building other developer tools (Sourcery uses it)

You can follow me on Twitter for news/updates about other projects I am creating.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.