Meta-programming for Swift, stop writing boilerplate code.

Overview

CircleCI

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!

TL;DR

Sourcery allows you to get rid of repetitive code and create better architecture and developer workflows. An example might be implementing Mocks 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 > 0
    }
    var sayHelloWithNameReceivedName: String?
    var sayHelloWithNameReceivedInvocations: [String] = []
    var sayHelloWithNameClosure: ((String) -> Void)?

    func sayHelloWith(name: String) {
        sayHelloWithNameCallsCount += 1
        sayHelloWithNameReceivedName = name
        sayHelloWithNameReceivedInvocations.append(name)
        sayHelloWithNameClosure?(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 BetaSetting? 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.

Installation

  • Binary form

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

  • Homebrew

    brew install sourcery

  • CocoaPods

    Add pod 'Sourcery' to your Podfile 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 $PODS_ROOT/Sourcery/bin/sourcery

    If you only want to install the sourcery binary and its lib_InternalSwiftSyntaxParser.dylib dependency, you may want to use the CLI-Only subspec: 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

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

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

    • Building with Xcode

      Generate xcodeproj with swift package generate-xcodeproj

      Open Sourcery.xcworkspace and build with Sourcery-Release scheme. This will create Sourcery.app in the Derived Data folder. You can copy it to your desired destination and run with path_to_sourcery_app/Sourcery.app/Contents/MacOS/Sourcery

Documentation

Full documentation for the latest release is available here.

Usage

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 <sources path> --templates <templates path> --output <output path>

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 --sources option.
  • --templates - Path to templates. File or Directory. You can provide multiple paths using multiple --templates options.
  • --force-parse - File extensions of Sourcery generated file you want to parse. You can provide multiple extension using multiple --force-parse options. (i.e. file.toparse.swift will be parsed even if generated by Sourcery if --force-parse toparse). Useful when trying to implement a multiple phases generation. --force-parse can also be used to process within a sourcery annotation. For example to process code within sourcery:inline:auto:Type.AutoCodable 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 true value. Arguments should be separated with , without spaces (i.e. --args arg1=value,arg2). Arguments are accessible in templates via argument.name
  • --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 .sourcery.yml configuration file:

sources:
  - <sources path>
  - <sources path>
templates:
  - <templates path>
  - <templates path>
force-parse:
  - <string value>
  - <string value>
output:
  <output path>
args:
  <name>: <value>

Read more about this configuration file here.

Issues

If you get unverified developer warning when using binary zip distribution try: xattr -dr com.apple.quarantine Sourcery-1.1.1

Contributing

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.

Sponsoring

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

License

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

Attributions

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.

Comments
  • Ideas for better name that avoids linguistic ableism

    Ideas for better name that avoids linguistic ableism

    Congrats on a super neat project! I wish only that it had a better name.

    Ableist language is any word or phrase that intentionally or inadvertently targets an individual with a disability... Examples of ableist language include “crazy,” “insane,” “lame,” “dumb,” “retarded,” “blind,” “deaf,” “idiot,” “imbecile,” “invalid (noun),” “maniac,” “nuts,” “psycho,” “spaz.”

    Each of these words, when used flippantly, can be extremely insulting to individuals who find themselves with physical (“lame,” “invalid,” “dumb”) or mental (“crazy,” “retarded,” “psycho”) disabilities.

    (via here)

    Naming is a Hard Problem™ and I'm guilty of using this language too. I encourage you to consider a new name while this project is still new. Thanks!

    Edit: From your own Code of Conduct:

    Examples of behavior that contributes to creating a positive environment include:

    Using welcoming and inclusive language ... Showing empathy towards other community members

    enhancement help wanted 
    opened by jhersh 39
  • Homebrew support

    Homebrew support

    It would be nice to have Sourcery in Homebrew.

    Since it's part of the dev tooling, and not the build itself (arguably), I'd prefer not to use CocoaPods for this, but would still be nice to have easy updates with a dependency manager.

    enhancement help wanted 
    opened by radex 30
  • Failed to build project with xcode 11.4

    Failed to build project with xcode 11.4

    Hi, when i tried to build my project with new xcode 11.4 I had this issue with no error description.

    Using configuration file at '.sourcery.platform.yml'
    Scanning sources...
    	loadOrParse: 0.8185429573059082
    	resolution took 0.1482919454574585
    	combiningTypes: 0.16124391555786133
    	total: 0.9820070266723633
    Found 213 types.
    Loading templates...
    Loaded 6 templates.
    	Loading took 0.008983016014099121
    Generating code...
    error: 
    
    opened by bogdangolubcr 27
  • Should we flatten variables?

    Should we flatten variables?

    If a type inherits from another type, or implements given protocol, should the variables be available in the given type itself? e.g.

    protocol Something {
      var typeName: String { get }
    }
    
    struct Foo: Something {
    }
    
    1. Should we list typeName in Foo? if so should we add alternative variable so people can choose between inherited or direct variables?

    2. Also same question can be asked in regards to annotations, if the protocol specified type level annotation, should we flatten that into Foo ?

    @ilyapuchka what do you think?

    let's discuss 
    opened by krzysztofzablocki 25
  • Sourcery as a framework

    Sourcery as a framework

    Hi, here at Bending Spoons we decided to leverage Sourcery as a way to generate some code for our applications.

    To integrate, in the best possible way, Sourcery with our tooling we would like to embed it in our internal swift CLI.

    We are in the process of understanding what is the best way to do so before start coding. We think that the best way would be to have Sourcery as a framework, similarly to Carthage and Swiftlint. Both those projects have a CLI and a Kit and all the functionalities are exposed through API.

    What do you think about this approach? Is it something that you would considering doing? Do you suggest a different way to approach this problem? Cheers

    cc @lucaquerella

    let's discuss Ideas 
    opened by bolismauro 24
  • _InternalSwiftSyntaxParser error with 1.3.0

    _InternalSwiftSyntaxParser error with 1.3.0

    Steps to reproduce:

    $ brew install sourcery
    $ sourcery --version
    1.3.0
    $ git clone http://github.com/realm/SwiftLint
    $ cd SwiftLint
    $ git checkout 92061e8
    $ rm Source/SwiftLintFramework/Models/PrimaryRuleList.swift Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift Tests/LinuxMain.swift
    $ make sourcery 
    sourcery --sources Source/SwiftLintFramework/Rules --templates .sourcery/PrimaryRuleList.stencil --output .sourcery
    No config file provided or it does not exist. Using command line arguments.
    Scanning sources...
    error: The loaded '_InternalSwiftSyntaxParser' library is from a toolchain that is not compatible with this version of SwiftSyntax
    The loaded '_InternalSwiftSyntaxParser' library is from a toolchain that is not compatible with this version of SwiftSyntaxmake: *** [Source/SwiftLintFramework/Models/PrimaryRuleList.swift] Error 3
    $ xcode-select -p
    /Applications/Xcode-12.4.app/Contents/Developer
    $ xcodebuild -version
    Xcode 12.4
    Build version 12D4e
    
    opened by jpsim 23
  • Inherited method appears twice in allMethods

    Inherited method appears twice in allMethods

    Given the following class structure:

    protocol BaseProtocol {
    	var variable: Int { get }
    	func doSomething()
    }
    
    class BaseClass: BaseProtocol {
    	var variable: Int = 0
    	func doSomething() {}
    }
    
    protocol ExtendedProtocol: BaseClass {
    	var externdedVariable: Int { get }
    	func extendedDoSomething()
    }
    
    class ExtendedClass: BaseClass, ExtendedProtocol {
    	var externdedVariable: Int = 0
    	func extendedDoSomething() { }
    }
    

    When navigating the allMethods property of ExtendedProtocol, doSomething will appear twice, once with definedInTypeName = BaseClass and once with definedInTypeName = BaseProtocol. Interestingly, allVariables only contains variable once.

    Example stencil file:

    {% for protocol in types.protocols where protocol.name|hasSuffix:"ExtendedProtocol"  %}
    class Mock{{ protocol.name|replace:"Protocol","" }}: {{protocol.name}} {
    
    {% for variable in protocol.allVariables|!definedInExtension %}
        {{ variable.name }} coming from {{variable.definedInTypeName}}
    {% endfor %}
    
    {% for method in protocol.allMethods|!definedInExtension %}
        {{ method.name }} coming from {{method.definedInTypeName}}
    {% endfor %}
    
    }
    
    {% endfor %}
    

    This is particularly a problem when trying to generate mocks. Using the current AutoMockable.stencil, the generated mock will not compile, because all the helpers generated for doSomething will be created twice.

    opened by lordzsolt 23
  • NSCocoaErrorDomain Code=4

    NSCocoaErrorDomain Code=4

    I'm seeing an error whenever I try to generate files using Sourcery. The error looks like this:

    error: Error Domain=NSCocoaErrorDomain Code=4 "“SwiftTemplate” couldn’t be moved to “Mock.swifttemplate” because either the former doesn’t exist, or the folder containing the latter doesn’t exist." UserInfo={NSSourceFilePathErrorKey=/var/folders/4s/kz_7_74j6y9dgr4zv1zty5w40000gn/T/SwiftTemplate/0.16.0/.build/debug/SwiftTemplate, NSUserStringVariant=(
        Move
    ), NSDestinationFilePath=/Users/max/Library/Caches/Sourcery/Mock.swifttemplate/68oTZ5uoc%2FNLqYRTuvHnzYxhRGfxDXdvwT7dDod7lWc%3D, NSFilePath=/var/folders/4s/kz_7_74j6y9dgr4zv1zty5w40000gn/T/SwiftTemplate/0.16.0/.build/debug/SwiftTemplate, NSUnderlyingError=0x7f80c04e5800 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
    

    I'm seeing this error on Sourcery 0.16.0 as well as on the latest master branch. (I built the latter with Xcode 10.2). Running Mojave 10.14.4.

    I see two other issues that look like they're related, but both were closed without an apparent resolution. The suggestion to clean the ~/Library/Caches/Sourcery folder did not work for me.

    Related issues: https://github.com/krzysztofzablocki/Sourcery/issues/739 https://github.com/krzysztofzablocki/Sourcery/issues/741

    It also appears this PR (https://github.com/krzysztofzablocki/Sourcery/pull/744) was meant to fix the issue, but again I'm still seeing it on the latest master.

    bug 
    opened by maxmamis 23
  • Error in Xcode 10

    Error in Xcode 10

    I'm getting an error running Sourcery since I passed to Xcode 10 and updated Sourcery to 0.14.0:

    No config file provided or it does not exist. Using command line arguments.
    Scanning sources...
    Found 676 types.
    Loading templates...
    Loaded 5 templates.
    Generating code...
    error: Error Domain=NSOSStatusErrorDomain Code=-1 "kCFStreamErrorHTTPParseFailure / kCFSocketError / kCFStreamErrorDomainCustom / kCSIdentityUnknownAuthorityErr / qErr / telGenericError / dsNoExtsMacsBug / kMovieLoadStateError / cdevGenErr: Could not parse the request/response. /  / custom to the kind of stream in question  /  / queue element not found during deletion /  / not a SysErr, just a placeholder  /  / General error; gray cdev w/o alert" UserInfo={terminationReason=__ObjC.Process.TerminationReason, error=dyld: Symbol not found: __T0BOWV
      Referenced from: /Users/david/Library/Caches/Sourcery/AutoCodable.swifttemplate/../SourceryRuntime.framework/Versions/A/SourceryRuntime
      Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib
     in /Users/david/Library/Caches/Sourcery/AutoCodable.swifttemplate/../SourceryRuntime.framework/Versions/A/SourceryRuntime
    }
    
    opened by hartbit 22
  • Support annotation array detection

    Support annotation array detection

    Im trying to loop over repeated annotations, except sometimes they might not be repeated.

    How can I treat the annotation as an array even if it's only a single value?

    opened by samskiter 21
  • Add generics to types

    Add generics to types

    As stated in issue #551, current type declaration only provides a boolean flag stating whether a type has a generic declaration or not. This PR parses the list of generic types associated to a type declaration as an Array<String>. They can be accessed during generation through the property type.genericTypes. Default value (when type is not generic) is an empty array.

    opened by truizlop 20
  • Support for type method mocking

    Support for type method mocking

    This pull request is to address issue #1072: adding support for mocking class methods

    As no object is created when calling a class method, keeping track of calls is done on static variable and a reset method is added to reset the mock between tests

    opened by otusweb 0
  • Distributed actors

    Distributed actors

    Since Swift 5.7, Swift provides language-level support for distributed actors. Distributed actors can be defined using the distributed actor keywords. On distributed actors, one can define distributed methods using distributed func. For example:

    distributed actor HelloActor {
        init(actorSystem: ActorSystem) {
            self.actorSystem = actorSystem
        }
    
        distributed func hello() {
            print("Hello!")
        }
    }
    

    Sourcery currently does not seem to provide a way to inspect if an actor or method is declared as distributed, for example with an isDistributed property on Actor or Method.

    opened by Obbut 2
  • Incorrect attributes when @available have message

    Incorrect attributes when @available have message

    With code like this

    @available(iOS, introduced: 2.0, deprecated: 12.0, message: "No longer supported; please adopt WKWebView.")
    @_Concurrency.MainActor open class UIWebView : UIView, NSCoding, UIScrollViewDelegate {
    }
    

    The type attributes.available will return this

    [@available(iOS, introduced: 2.0, deprecated: 12.0, message: \)]
    

    Env

    Sourcery: 1.9.2 Xcode: Version 14.2 macOS: 13.1 (22C65)

    opened by EkkoG 0
  • SPM command plugin `the library '...' requires macos 10.13`

    SPM command plugin `the library '...' requires macos 10.13`

    I am new to Sources and setting up using SPM command plugin.

    • In the Package.swift file .package(url: "https://github.com/krzysztofzablocki/Sourcery.git", revision: "3a9e5f1014ac09b30727c01d2a0e1531dac30948") (use commit of 1.9.2 release, due to https://github.com/krzysztofzablocki/Sourcery/issues/1102 issue.)

    • $ swift package plugin --list output ‘sourcery-command’ (plugin ‘SourceryCommandPlugin’ in package ‘Sourcery’)

    • Running swift package --allow-writing-to-package-directory sourcery-command failed with error error: the library 'ArticleCardFeature' requires macos 10.13, but depends on the product 'ComposableArchitecture' which requires macos 10.15; consider changing the library 'ArticleCardFeature' to require macos 10.15 or later, or the product 'ComposableArchitecture' to require macos 10.13 or earlier. and the same error for every feature module.

    Do I miss something in configuration?

    opened by andriyslyusar 0
  • AutoLenses stencil template failing for nested types

    AutoLenses stencil template failing for nested types

    SelectCategoriesModel.swift

    enum SelectCategories {
      struct SelectCategoryViewModel {
        let id: String
        let text: String
        let imageName: String?
        let isSelected: Bool
      }
    }
    
    extension SelectCategories.SelectCategoryViewModel: AutoLenses { }
    

    Lens+Generated.swift

    extension SelectCategories.SelectCategoryViewModel {
      static let idLens = Lens<SelectCategories.SelectCategoryViewModel, String>(
        get: { $0.id },
        set: { id, selectcategories.selectcategoryviewmodel in
        
           SelectCategories.SelectCategoryViewModel(id: id, text: selectcategories.selectcategoryviewmodel.text, imageName: selectcategories.selectcategoryviewmodel.imageName, isSelected: selectcategories.selectcategoryviewmodel.isSelected)
        }
      )
      static let textLens = Lens<SelectCategories.SelectCategoryViewModel, String>(
        get: { $0.text },
        set: { text, selectcategories.selectcategoryviewmodel in
           SelectCategories.SelectCategoryViewModel(id: selectcategories.selectcategoryviewmodel.id, text: text, imageName: selectcategories.selectcategoryviewmodel.imageName, isSelected: selectcategories.selectcategoryviewmodel.isSelected)
        }
      )
      static let imageNameLens = Lens<SelectCategories.SelectCategoryViewModel, String?>(
        get: { $0.imageName },
        set: { imageName, selectcategories.selectcategoryviewmodel in
           SelectCategories.SelectCategoryViewModel(id: selectcategories.selectcategoryviewmodel.id, text: selectcategories.selectcategoryviewmodel.text, imageName: imageName, isSelected: selectcategories.selectcategoryviewmodel.isSelected)
        }
      )
      static let isSelectedLens = Lens<SelectCategories.SelectCategoryViewModel, Bool>(
        get: { $0.isSelected },
        set: { isSelected, selectcategories.selectcategoryviewmodel in
           SelectCategories.SelectCategoryViewModel(id: selectcategories.selectcategoryviewmodel.id, text: selectcategories.selectcategoryviewmodel.text, imageName: selectcategories.selectcategoryviewmodel.imageName, isSelected: isSelected)
        }
      )
    }
    

    It fails to compile because the setter parameter name matches the type name, which contains a dot character.

    opened by nmarkovic04 1
  • Unable to honor environment variables that end in

    Unable to honor environment variables that end in "=="

    I have a secret that ends in "==" and am having trouble using sourcery to convert that secret into my stencil.

    Steps to reproduce:

    1. Install Sourcery with brew brew install sourcery
    2. Create a simple stencil, Secrets.stencil like the following
    public struct Secrets {
        public var vendor: VendorSecrets
        
        public struct VendorSecrets {
            public var credentials: String
        }
    }
    
    public var secrets = Secrets(
        vendor: .init(
            credentials: "{{ argument.VENDOR_CREDENTIALS }}"
        )
    )
    
    1. Run the following command in a terminal
    export VENDOR_CREDENTIALS="banana==" && sourcery \
        --templates . \
        --sources . \
        --output . \
        --args VENDOR_CREDENTIALS=$VENDOR_CREDENTIALS
    

    Result: Sourcery will produce Secrets.generated.stencil that looks like the following

    // Generated using Sourcery 1.9.0 — https://github.com/krzysztofzablocki/Sourcery
    // DO NOT EDIT
    public struct Secrets {
        public var vendor: VendorSecrets
    
        public struct VendorSecrets {
            public var credentials: String
        }
    }
    
    public var secrets = Secrets(
        vendor: .init(
            credentials: "1" // Uh oh
        )
    )
    

    Expected result: Sourcery will produce Secrets.generated.stencil that looks like the following

    // Generated using Sourcery 1.9.0 — https://github.com/krzysztofzablocki/Sourcery
    // DO NOT EDIT
    public struct Secrets {
        public var vendor: VendorSecrets
    
        public struct VendorSecrets {
            public var credentials: String
        }
    }
    
    public var secrets = Secrets(
        vendor: .init(
            credentials: "banana=="
        )
    )
    

    OS: macOS 12.6.1 (M1 Max)

    opened by piofusco 0
Releases(1.9.2)
  • 1.9.2(Dec 7, 2022)

  • 1.9.1(Dec 6, 2022)

    What's Changed

    • Add support for public protocols in AutoMockable template by @gspiers in https://github.com/krzysztofzablocki/Sourcery/pull/1100
    • Add support for async and throwing properties to AutoMockable template by @gspiers in https://github.com/krzysztofzablocki/Sourcery/pull/1101
    • Added support for actors by @bscothern-Cricut in https://github.com/krzysztofzablocki/Sourcery/pull/1112
    • Fixed a typo from my last PR by @bscothern-Cricut in https://github.com/krzysztofzablocki/Sourcery/pull/1114
    • Add .pre-commit-hooks.yaml by @Cyberbeni in https://github.com/krzysztofzablocki/Sourcery/pull/1115
    • Fixed parsing of extensions and nested types in swiftinterface files by @till0xff in https://github.com/krzysztofzablocki/Sourcery/pull/1113
    • Improves performance

    New Contributors

    • @gspiers made their first contribution in https://github.com/krzysztofzablocki/Sourcery/pull/1100
    • @bscothern-Cricut made their first contribution in https://github.com/krzysztofzablocki/Sourcery/pull/1112

    Full Changelog: https://github.com/krzysztofzablocki/Sourcery/compare/1.9.0...1.9.1

    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.9.1.zip(6.78 MB)
  • 1.9.0(Oct 6, 2022)

  • 1.8.2(Jul 28, 2022)

    What's Changed

    • Add a flag to parse serially by @erichoracek in https://github.com/krzysztofzablocki/Sourcery/pull/1063
    • Update .swift-version to 5.5 by @liamnichols in https://github.com/krzysztofzablocki/Sourcery/pull/1070
    • Build .swifttemplate in release mode by @jimmya in https://github.com/krzysztofzablocki/Sourcery/pull/1075
    • Added deletingLastComponent to string filter by @markst in https://github.com/krzysztofzablocki/Sourcery/pull/1076
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.8.2.zip(26.37 MB)
  • 1.8.1(Apr 24, 2022)

    What's Changed

    • Support compiling project with Swift 5.5 by @liamnichols in https://github.com/krzysztofzablocki/Sourcery/pull/1049
    • Revert to using 'swift build' with sandbox disabled for 'rake build' by @liamnichols in https://github.com/krzysztofzablocki/Sourcery/pull/1057
    • Updated Stencil to 0.14.2

    Full Changelog: https://github.com/krzysztofzablocki/Sourcery/compare/1.8.0...1.8.1

    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.8.1.zip(26.36 MB)
  • 1.8.0(Mar 28, 2022)

    New Features

    • Adds xcframework key to target object in configuration file to enable processing of swiftinterface

    Fixes

    • Fixed issues generating Swift Templates when using Xcode 13.3 #1040
    • Modifications to included files of Swift Templates now correctly invalidate the cache - #889

    Internal Changes

    • Swift 5.6 and Xcode 13.3 is now required to build the project
    • lib_internalSwiftSyntaxParser is now statically linked enabling better support when installing through SPM and Mint #1037
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.8.0.zip(25.88 MB)
  • 1.7.0(Feb 26, 2022)

    New Features

    • Adds fileName to Type and exposes path as well
    • Adds support for parsing async methods, closures and variables

    Fixes

    • correct parsing of rawValue initializer in enum cases, fixes #1010
    • Use name or path parameter to parse groups to avoid duplicated group creation, fixes #904, #906
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.7.0.zip(23.94 MB)
  • 1.6.1(Dec 9, 2021)

  • 1.6.0(Sep 26, 2021)

    • Update dependencies to fix build on Xcode 13 and support Swift 5.5 #989
    • Improves performance in large codebases (it's more than 50% faster than 1.5.0)
    • Skips hidden files / directories and doesn't step into packages
    • added after-auto: generation mode to inline codegen
    • Fixes unstable ordering of TypeName.attributes
    • Fixing Type.uniqueMethodFilter(_:_:) so it compares return types of methods as well.
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.6.0.zip(19.77 MB)
  • 1.5.0(Jul 21, 2021)

    Features

    • Adds support for variadic parameters in functions
    • Adds support for parsing property wrappers
    • Added titleCase filter that turns somethingNamedLikeThis into Something Named Like This

    Fixes

    • correct passing force-parse argument to specific file parsers and renames it to forceParse to align with other naming
    • corrects isMutable regression on protocol variables #964
    • Added multiple targets to link
    • Fix groups creation
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.5.0.zip(7.39 MB)
  • 1.4.2(May 12, 2021)

    Fixes

    • Fix a test failing on macOS 11.3
    • Fix generation of inline:auto annotations in files with other inline annotations.
    • Fixes modifier access for things like isLazy, isOptional, isConvienceInitializer, isFinal
    • Fixes isMutable on subscripts
    • Fixes open access parsing
    • Removes symlinks in project, since these can confuse Xcode
    • Fixes inout being incorrectly parsed for closures

    New Feature

    • Updated to Swift / SwiftSyntax 5.4
    • Added ability to parse inline code generated by sourcery if annotation ends with argument provided in --force-parse option
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.4.2.zip(7.38 MB)
  • 1.4.1(Apr 20, 2021)

  • 1.4.0(Apr 14, 2021)

    Features

    • Added allImports property to Type, which returns all imports existed in all files containing this type and all its super classes/protocols.
    • Added basedTypes property to Type, which contains all Types this type inherits from or implements, including unknown (not scanned) types with extensions defined.
    • Added inference logic for basic generics from variable initialization block
    • Added newline and typed stencil tags from Sourcery Pro

    Fixes

    • Fixed inferring raw value type from inherited types for enums with no cases or with associated values
    • Fixed access level of protocol members
    • Fixes parsing indirect enum cases correctly even when inline documentation is used
    • Fixes TypeName.isClosure to handle composed types correctly
    • Fixes issue where Annotations for Protocol Composition types are empty
    • Fixes sourcery:inline:auto position calculation when the file contains UTF16 characters
    • Fixes sourcery:inline:auto position calculation when the file already contains code generated by Sourcery

    Internal changes

    • Removes manual parsing of TypeName, only explicit parser / configuration is now used
    • Updted SwiftLint, Quick and Nible to latest versions
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.4.0.zip(7.28 MB)
  • 1.3.4(Mar 12, 2021)

  • 1.3.3(Mar 10, 2021)

    Fixes

    • Fixes information being lost when extending unknown type more than once
    • Multiple configuration files can be now passed through command line arguments

    Templates

    • AutoEquatable will use type.accessLevel for it's function, closes #675

    Internal changes

    • If you are using .swifttemplate in your configuration you might notice performance degradation, this is due to new composer added in 1.3.2 that can create memory graph cycles between AST with which our current persistence doesn't deal properly, to workaround this we need to perform additional work for storing copy of parsed AST and compose it later on when running SwiftTemplates. This will be fixed in future release when AST changes are brought in, if you notice too much of a performance drop you can just switch to 1.3.1.
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.3.3.zip(7.26 MB)
  • 1.3.2(Mar 7, 2021)

    New Features

    • Configuration file now supports multiple configurations at once

    Fixes

    • When resolving extensions inherit their access level for methods/subscripts/variables and sub-types fixes #910
    • When resolving Parent.ChildGenericType properly parses generic information

    Internal changes

    • Faster composing phase
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.3.2.zip(7.24 MB)
  • 1.3.1(Mar 4, 2021)

  • 1.3.0(Mar 3, 2021)

    Internal changes

    • Sourcery is now using SwiftSyntax not SourceKit
    • Performance is significantly improved
    • Memory usage for common case (cached) is drastically lowered

    Configuration changes

    • added logAST that will cause AST warnings and errors to be logged, default false
    • added logBenchmarks that will cause benchmark informations to be logged, default false

    AST Data Changes

    • initializers are now considered as static method not instance
    • typealiases and protocol compositions now provide proper accessLevel
    • if a tuple arguments are unnamed their name will be automatically set to index
    • default accessLevel when not provided in code is internal everywhere
    • Added modifiers to everything that had attributes and split them across, in sync with Swift naming
    • block annotations will be applied to associated values that are inside them
    • extensions of unknown types will not have the definition module name added in their globalName property. (You can still access it via module)
    • if you had some weird formatting around syntax declarations (newlines in-between etc) the AST data should be cleaned up rather than trying to reproduce that style
    • Imports are now proper types, with additional information
    • Protocol now has genericRequirements, it will also inherit associatedType from it's parent if it's not present
    • Single value tuples will be automatically unwrapped when parsing

    Attributes

    • Attributes are now of stored in dictionary of arrays [String: [Attribute]] since you can have multiple attributes of the same name e.g. @available
    • Name when not named will be using index same as associated value do e.g. objc(name) will have 0: name as argument
    • spaces will no longer be replaced with _

    Troubleshooting

    • If you want to use Sourcery as framework you'll need to use SPM integration since SwiftSyntax doesn't have Podspec
    • If you run into dylib issue it means your Xcode isn't in default location, simple symlink should work
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.3.0.zip(4.67 MB)
  • 1.2.0(Feb 13, 2021)

  • 1.1.1(Feb 9, 2021)

  • 1.1.0(Feb 7, 2021)

    New Features

    • PR Methods, Variables and Subscripts are now uniqued in all accessors:
      • methods and allMethods
      • variables and allVariables
      • subscripts and allSubscripts
      • New accessor is introduced that doesn't get rid of duplicates rawMethods, rawVariables, rawSubscriptss.
      • The deduping process works by priority order (highest to lowest):
        • base declaration
        • inheritance
        • protocol conformance
        • extensions
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.1.0.zip(24.83 MB)
  • 1.0.3(Jan 29, 2021)

    Internal Changes

    • updated xcodeproj, Stencil and StencilSwiftKit to newest versions

    Bug fixes

    • Fixes type resolution when using xcode project integration
    • Matches the behaviour of allMethods to allVariables by only listing the same method once, even if defined in both base protocol and extended class. You could still walk the inheritance tree if you need to (to get all original methods), but for purpose of majority of codegen this is unneccessary.
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.0.3.zip(24.74 MB)
  • 1.0.2(Nov 29, 2020)

    Bug fixes

    • Fixes an issue when a very complicated variable initialization that contained .init call to unrelated case would cause the parser to assume the whole codeblock was a type and that could lead to mistakes in processing and even stack overflows
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.0.2.zip(22.94 MB)
  • 1.0.1(Nov 27, 2020)

    Internal Changes

    • Updated project and CI to Xcode 12.1
    • Updated SourceKitten, Commander.

    Bug fixes

    • Fix multiline method declarations parsing
    • Fix an issue, where "types.implementing." did not work due to an additional module name.
    • Using tuple for associated values in enum case is deprecated since Swift 5.2. Fix AutoEquatable and AutoHashable templates to avoid the warning (#842)
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.0.1.zip(22.92 MB)
  • 1.0.0(Aug 14, 2020)

    New Features

    • Added support for associated types (#539)

    Bug fixes

    • Disallow protocol compositions from being considered as the rawType of an enum (#830)
    • Add missing documentation for the ProtocolComposition type.
    • Fix incorrectly taking closure optional return value as sign that whole variable is optional (#823)
    • Fix incorrectly taking return values with closure as generic type as sign that whole variable is a closure (#845)
    • Fix empty error at build time when using SwiftTemplate on Xcode 11.4 and higher (#817)
    Source code(tar.gz)
    Source code(zip)
    Sourcery-1.0.0.zip(13.57 MB)
  • 0.18.0(Apr 28, 2020)

    New Features

    • Added optional filter for variables
    • Added json filter to output raw JSON objects
    • Added .defaultValue to AssociatedValue
    • Added support for parsing Protocol Compositions
    • Added support for parsing free functions
    • Added support for indirect enum cases
    • Added support for accessing all typealiases via typealiases and typesaliasesByName
    • Added support for parsing global typealiases

    Internal Changes

    • Improved error logging when running with --watch option
    • Updated CI to Xcode 11.4.1

    Bug fixes

    • Fixed expansion of undefined environment variables (now consistent with command line behaviour, where such args are empty strings)
    • Fixed a bug in inferring extensions of Dictionary and Array types
    • Fixed a bug that was including default values as part of AssociatedValues type names
    • Fixed an issue with AutoMockable.stencil template when mocked function's return type was closure
    • Fixed missing SourceryRuntime dependency of SourceryFramework (SPM)
    Source code(tar.gz)
    Source code(zip)
    Sourcery-0.18.0.zip(13.53 MB)
  • 0.17.0(Sep 3, 2019)

    Internal Changes

    • Parallelized combining phase that yields 5-10x speed improvement for New York Times codebase
    • Switched cache logic to rely on file modification date instead of content Sha256
    • Additional benchmark logs showing how long does each phase take
    • update dependencies to fix cocoapods setup when using Swift 5.0 everywhere. Update Quick to 2.1.0, SourceKitten to 0.23.1 and Yams to 2.0.0
    Source code(tar.gz)
    Source code(zip)
    Sourcery-0.17.0.zip(13.96 MB)
  • 0.16.2(Jul 18, 2019)

  • 0.16.1(Apr 29, 2019)

    Bug fixes

    • Fix ReceivedInvocations's type for the method which have only one parameter in AutoMockable.stencil
    • Fix missing folder error that could happen when running a Swift template with existing cache
    • Don't add indentation to empty line when using inline generated code.

    Internal Changes

    • Removed dependency on SwiftTryCatch pod in order to avoid Swift Package Manager errors.
    Source code(tar.gz)
    Source code(zip)
    Sourcery-0.16.1.zip(14.75 MB)
Owner
Krzysztof Zabłocki
Making Swift engineers more efficient through tools and workflows.  My code powers up over 70 000+ apps.
Krzysztof Zabłocki
Objective-c code Apple style documentation set generator.

About appledoc IMPORTANT NOTICE: collaborators needed appledoc is command line tool that helps Objective-C developers generate Apple-like source code

tomaz 4.2k Dec 20, 2022
An Xcode plug-in to format your code using SwiftLint.

SwiftLintXcode An Xcode plug-in to format your code using SwiftLint. Runs swiftlint autocorrect --path CURRENT_FILE before *.swift file is saved. IMPO

Yuya Tanaka 348 Sep 18, 2022
Swift CLI for strong-typing images, colors, storyboards, fonts and localizations

Shark Shark is a Swift command line tool that generates type safe enums for your images, colors, storyboards, fonts and localizations. Because Shark r

Kaan Dedeoglu 377 Dec 1, 2022
Strong typed, autocompleted resources like images, fonts and segues in Swift projects

R.swift Get strong typed, autocompleted resources like images, fonts and segues in Swift projects Why use this? It makes your code that uses resources

Mathijs Kadijk 8.9k Jan 6, 2023
Soulful docs for Swift & Objective-C

jazzy is a command-line utility that generates documentation for Swift or Objective-C About Both Swift and Objective-C projects are supported. Instead

Realm 7.2k Jan 3, 2023
swiftenv allows you to easily install, and switch between multiple versions of Swift.

Swift Version Manager swiftenv allows you to easily install, and switch between multiple versions of Swift. This project was heavily inspired by pyenv

Kyle Fuller 1.9k Dec 27, 2022
Script to support easily using Xcode Asset Catalog in Swift.

Misen Misen is a script to support using Xcode Asset Catalog in Swift. Features Misen scans sub-directories in the specified Asset Catalog and creates

Kazunobu Tasaka 123 Jun 29, 2022
An Xcode Plugin to convert Objective-C to Swift

XCSwiftr Convert Objective-C code into Swift from within Xcode. This plugin uses the Java applet of objc2swift to do the conversion. Noticed that the

Ignacio Romero Zurbuchen 338 Nov 29, 2022
Swift autocompleter for Sublime Text, via the adorable SourceKitten framework

SwiftKitten SwiftKitten is a Swift autocompleter for Sublime Text, via the adorable SourceKitten framework. Faster than XCode ! This package is new an

John Snyder 142 Sep 9, 2022
A meta library to provide a better `Delegate` pattern.

Delegate A meta library to provide a better Delegate pattern described here and here. Usage Instead of a regular Apple's protocol-delegate pattern, us

Wei Wang 67 Dec 23, 2022
Basic Stop Watch & Countdown app for iOS devices. Created for learning purpose.

stopwatch Basic Stop Watch (included Countdown feature) app for iOS devices. Created for learning purpose. How to use Just download source code and un

Jogendra 5 Jun 11, 2022
Preview with Link's meta information.(SwiftUI)

LinkPreview(SwiftUI) Preview with Link's meta information. Image Gif Get Started import SwiftUI import LinkPreview struct LinkPreview_Test: View {

null 15 Dec 16, 2022
Preview with Link's meta information with SwiftUI

LinkPreview(SwiftUI) Preview with Link's meta information. Image Gif Get Started import SwiftUI import LinkPreview struct LinkPreview_Test: View {

null 15 Dec 16, 2022
Covidapp - Stop COVID-19 Hrvatska

Stop COVID-19 Hrvatska Description Kako bi usporili širenje bolesti COVID-19 međ

null 0 Feb 12, 2022
Template repository for quickly creating boilerplate code for a SwiftUI macOS app.

Sidebar App This is a template repository for quickly creating boilerplate code for a SwiftUI macOS app. License This app is released into the public

apparata 22 Dec 18, 2022
This is a template repository for quickly creating boilerplate code for a SwiftUI macOS menu bar app.

Menu Bar App This is a template repository for quickly creating boilerplate code for a SwiftUI macOS menu bar app. License This app is released into t

apparata 5 Dec 6, 2022
NV_MVVM-C is a template file generator. This can reduce the time taken to write the boilerplate code and create the files.

NV_MVVM-C Template, is an MVVM-C Boilerplate generator which will help you generate all the necessary files for your project architected in MVVM-C.

Nikhil Vinod 9 Sep 6, 2022
Eliminate your Core Data boilerplate code

SSDataKit There is a lot of boilerplate code required to write a Core Data application. This is annoying. In pretty much everything I've written since

Sam Soffes 456 Dec 21, 2022
Boilerplate-free mocking framework for Swift!

Cuckoo Mock your Swift objects! Introduction Cuckoo was created due to lack of a proper Swift mocking framework. We built the DSL to be very similar t

Brightify 1.5k Dec 27, 2022
The easiest Future and Promises framework in Swift. No magic. No boilerplate.

Promis The easiest Future and Promises framework in Swift. No magic. No boilerplate. Overview While starting from the Objective-C implementation of Ju

Alberto De Bortoli 111 Dec 27, 2022