Latest 0.2.0
License MIT
Platforms osx , ios , tvos , watchos


Pure-Swift meta-programming

Proof-of-concept pure Swift code-generator that runs on top of Sourcery.


Sourcerer consists of a series of swift modules that you can import into your macOS application to load the information that Sourcery extracts from Swift sources, the SourceryRuntime.Types object.

  • SourcererArchiver uses Sourcery to write an archive of the SourceryRuntime.Types object to the disk.
  • SourcererUnarchiver unarchives the SourceryRuntime.Types object into the running application.
  • SourceryRuntime is required by the unarchiver to load the archive information.
  • SourcererTypes and SourcererRenderer contain some helpers and extensions to SourceryRuntime.Types.

Sample project

The sample project is a command-line tool that extracts metrics (not necessarily 100% accurate) from the analyzed sources.

To see what the generated reports look like, check the Samples folder. There you can find the result of analyzing Sourcery’s source code with sourcerer.

To see how it works, take a look at the sample sources:

$ git clone
$ cd swift-sourcerer
$ pod install
$ open sourcerer.xcworkspace

Note: after pod install you may see the following message:

[!] The version of CocoaPods used to generate the lockfile (1.6.0.beta.2) is higher than the version of the current executable (1.5.3). Incompatibility issues may arise.

In that case, you need to install CocoaPods 1.6.0.beta.2 and run pod install again:

$ gem install cocoapods --pre
$ pod install


Steps to get started using Sourcerer in your own project:

  • Create a new macOS project (e.g. Example):

  • Set up dependencies (Podfile):
target 'Example' do
  # archive
  pod 'SourcererArchiver', :git => ''
  # unarchive
  pod 'SourcererUnarchiver', :git => ''
  pod 'SourceryRuntime', :git => ''
  • Download SourceryRuntime sources:


  • Implement initial code (main.swift):
import SourceryRuntime
import SourcererArchiver
import SourcererUnarchiver

let ignoreUnknownArguments = false
let archive = GenerateTypesArchive().execute
let unarchive = UnarchiveTypesFromPath().execute

let typesArchivePath = try archive(ignoreUnknownArguments)
let types = try unarchive(typesArchivePath)

print("- There are (types.protocols.count) protocols.")
print("- There are (types.structs.count) structs.")
print("- There are (types.classes.count) classes.")
  • When executing this example you need to pass: (1) the path to the Sourcery executable (--sourcery-path) and (2) the path to the sources (--sources):

Example --sourcery-path /path/to/sourcery --sources /path/to/sources/

Latest podspec

    "name": "sourcerer",
    "version": "0.2.0",
    "summary": "Swift source code metrics generator",
    "description": "Proof-of-concept pure Swift code-generator that runs on top of [Sourcery](",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "Hu00e8ctor Marquu00e8s": "[email protected]"
    "social_media_url": "",
    "source": {
        "http": ""
    "preserve_paths": "*",
    "exclude_files": "**/",
    "platforms": {
        "osx": null,
        "ios": null,
        "tvos": null,
        "watchos": null

Pin It on Pinterest

Share This