SwiftyMocky is available through:

1. CocoaPods.

To install it, simply add the following line to your Podfile:

pod "SwiftyMocky"

Then execute pod install

The integration part is described in setup page.

2. Carthage.

To install, add following to you Cartfile:

github "MakeAWishFoundation/SwiftyMocky"

Then execute carthage update

For Carthage, few additional steps are required:

  1. Obtain Sourcery - used to generate mocks (specify valid path in generate mock) - you can use get_sourcery script below
  2. Change templates path to Carthage/Build/iOS/SwiftyMocky.framework/
  3. In your test target add to:
    • Other Swift Flags: -DMocky
  4. In your test target, add SwiftyMocky to linked libraries:

    Link binary

  5. In your test target, add new copy files phase:

    Link binary

  6. Select destination to frameworks, and add SwiftyMocky:

    Link binary

The integration part is described in setup page.

3. Manually.

Include Sources in your project, and setup Sourcery

The integration part is described in setup page.


Main difference between how SwiftyMocky is installed, is location of sourcery binary and templates, used to generate Mocks. Whatever you choose, make sure that correct paths are setup for mocky.yml, and sourcery call.

Support for other swift versions

Download/build Sourcery binary manually, or use prebuilt sourcery versions from:

Currentyly we support:

  • 5.0
  • 4.2
  • 4.1
  • 4.0.2
  • 4.0

Usage from root project dir:

sh # Will download 5.0 by default
sh 5.0 # or 4.2, if you use Xcode 10.1

[[ $# > 0 ]] && VERSION="$1" || VERSION="5.0"
[[ $# > 1 ]] && OUTPUT="$2" || OUTPUT="./Pods/Sourcery/bin"
SOURCERY_VERSION="0.16.0" # The version of Sourcery that is associated with this SwiftyMocky version

rm -r -f "$OUTPUT"
git clone -b "sourcery/$SOURCERY_VERSION-swift$VERSION" --single-branch --depth 1 "$OUTPUT"

Note! This script is also shipped with SwiftyMocky when installing via cocoapods You can use it from project root like sh ./Pods/SwiftyMocky/ 4.2 Version is optional, if you don’t specify it, script will use latest supported (5.0 in that case)

Note 2! If you use Carthage, you should specify your custom output location for sourcery binary. Please have in mind, that script clears output dir, so don’t point it to ~/ or something ;)