Skip to content
🏭 Generate boilerplate of factory Swift framework 🏭
Swift Ruby Other
Branch: master
Clone or download
Pull request Compare This branch is 2 commits ahead, 62 commits behind Nonchalant:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
FactoryProvider.xcodeproj
FactoryProviderMain
Generator
Source
.gitignore
.swift-version
.travis.yml
FactoryProvider.podspec
FactoryProviderMain.plist
LICENSE.md
Makefile
README.md

README.md

🏭 FactoryProvider 🏭

Build Status Version Platform GitHub license GitHub release Xcode Swift Swift Package Manager

Generate boilerplate of factory Swift framework.

Requirements

FactoryProvider works on the following platforms:

  • iOS 8+
  • Mac OSX 10.9+
  • watchOS 2+
  • tvOS 9+

Supports

Struct, Enum

FactoryProvider

1. Installation

CocoaPods

FactoryProvider runtime is available through CocoaPods. To install it, simply add the following line to your test target in your Podfile:

pod "FactoryProvider"

And add the following Run script build phase to your test target's Build Phases:

"${PODS_ROOT}/FactoryProvider/generate" \
    "${PROJECT_DIR}/${PROJECT_NAME}"/Input1/**/*.swift \
    "${PROJECT_DIR}/${PROJECT_NAME}"/Input2/**/*.swift \
    --exclude "${PROJECT_DIR}/${PROJECT_NAME}/Input2/InputFile.swift" \
    --testable "$PROJECT_NAME" \
    --output "$PROJECT_DIR/${PROJECT_NAME}Tests/Factories.generated.swift"

After running once, locate Factories.generated.swift and drag it into your Xcode test target group.

--include

path of files to generate

--exclude

path of files not to generate

--testable

testable target

--output

path of generated file

2. Usage

You can get a instance to call <TypeName>.provide(). Each properties are set to default value.

struct Climber {
    let name: String
    let age: Int
}

let climber = Climber.provide()

3. Lens

<TypeName>.provide() provides fixed instance. You can modify each property by Lens.

Get

let name = Climber._name.get(Climber.provide())
// ""

Set

let climber = Climber._name.set(Climber.provide(), "Climber")
// Climber(name: "Climber", age: 0)

Modify

let climber1 = Climber._name.set(Climber.provide(), "Climber")
// Climber(name: "Climber", age: 0)

let climber = Climber._name.modify(climber1, f: { $0 + $0 })
// Climber(name: "ClimberClimber", age: 0)

Compose

struct Climber {
    let id: Id
    let name: String
    
    struct Id {
        let value: String
    }
}

let climber1 = Climber.provide()
// Climber(id: Id(value: ""), name: "")

let climber2 = Climber._id.compose(other: Climber.Id._value).set(climber1, "id")
// Climber(id: Id(value: "id"), name: "")

Libraries

License

FactoryProvider is available under the MIT License.

You can’t perform that action at this time.