Inlinit 0.1.2

Inlinit 0.1.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jan 2016
SPMSupports SPM

Maintained by Jo Albright.


Downloads

Total116
Week0
Month0

Installs

Apps7
Test Targets1
powered by Segment

GitHub

Stars6
Watchers0
Forks0
Issues0
Contributors1
Pull Requests0

Code

Files1
LOCLines of Code 11


Inlinit 0.1.2

A new design pattern to allow closure initialization.

Usage

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

Motivation

The desire is to initialize within a closure for unique customization while allowing the ability to use constants.

Example 1

Previous Code

// needs to be "var" to allow append below
var randomNumbersArray: [Int] = []

for _ in 0...10 {

    randomNumbersArray.append(Int(arc4random_uniform(100)))

}

New Code

// can now use let and append within initializer closure
let randomNumbersArray: [Int] {

    for _ in 0...10 {

        $0.append(Int(arc4random_uniform(100)))

    }

}
Example 2
struct Person: Inlinit {

    var age: Int = 0
    var name: String?

}

// initialize & set properties
var me = Person {

    $0.name = "Jo"
    $0.age = 32

}

// update properties
me <- {

    $0.age = 30
    $0.name = "John"

}
Example 3
func newLabel(text: String) -> UILabel {

    let label: UILabel = UILabel(frame: CGRect(x: 10, y: 10, width: 100, height: 40))

    label.text = text
    label.textColor = UIColor.magentaColor()

    return label

}

newLabel("This is lame...")

New Code

func newLabel(text: String) -> UILabel {

    return UILabel {

        $0.frame = CGRect(x: 10, y: 10, width: 100, height: 40)
        $0.textColor = UIColor.magentaColor()

    }.text = text

}

newLabel("This is Awesome!")

So many possibilities unlocked with this new design pattern

Installation

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

pod "Inlinit"

Inlinit is also available through Swift Package Manager. Please take a look at the link to learn more about how to use SPM.

import PackageDescription

let package = Package(
    name: "YOUR_PACKAGE_NAME",
    dependencies: [
        .Package(url: "https://github.com/joalbright/Inlinit.git", majorVersion: 0)
    ]
)

Author

Jo Albright

License

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