Latest 0.1.0
Homepage https://github.com/onmyway133/Configurable
License MIT
Platforms ios 8.0, requires ARC
Authors

Configure objects using block

[![CI Status](http://img.shields.io/travis/Khoa Pham/Configurable.svg?style=flat)](https://travis-ci.org/Khoa Pham/Configurable)
Version
License
Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

How it works

  • Use @noescape to make sure parameter can not outlive the method call
  • Does not work well on struct, unless we use mutating
  • Configurable conformance was declared for NSObject
  • Initable conformance must be explictly declared

Features

Build

Works on any mutable value

let person = build(Person()) {
    $0.name = "Luke Skywalker"
    $0.age = 17
}

XCTAssert(person.name! == "Luke Skywalker")
XCTAssert(person.age! == 17)

Configurable

Works on NSObject subclasses

let button = UIButton(type: .Custom).configure {
    $0.setTitle("Click", forState: .Normal)
    $0.setTitleColor(UIColor.redColor(), forState: .Normal)
}

XCTAssert(button.titleForState(.Normal)! == "Click")
XCTAssert(button.titleColorForState(.Normal)! == UIColor.redColor())

Works on custom class

class Person {
    var name: String?
    var age: Int?

    init() {

    }
}

extension Person: Configurable {}

let person = Person().configure {
    $0.name = "Luke Skywalker"
    $0.age = 17
}

XCTAssert(person.name! == "Luke Skywalker")
XCTAssert(person.age! == 17)

Initable

Works on classes that have init()

extension UILabel: Initable {}

let label = UILabel {
    $0.text = "Fantageek"
}

XCTAssert(label.text == "Fantageek")

Works on custom classes

final class Robot {
    var name: String?
    var cute = false
}
extension Robot: Initable { }

let robot = Robot {
    $0.name = "R2-D2"
    $0.cute = true
}

XCTAssert(robot.name == "R2-D2")
XCTAssert(robot.cute)

Custom classes need to be final

final class Robot {
    var name: String?
    var cute = false
}

or implement init()

class Robot {
    var name: String?
    var cute = false

    required init() {

    }
}

Installation

Configurable is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Configurable"

Credit

Credit goes to

Author

Khoa Pham, [email protected]

License

Configurable is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Configurable",
    "version": "0.1.0",
    "summary": "Configure objects using block.",
    "homepage": "https://github.com/onmyway133/Configurable",
    "license": "MIT",
    "authors": {
        "Khoa Pham": "[email protected]"
    },
    "source": {
        "git": "https://github.com/onmyway133/Configurable.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "Configurable": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This