Latest 0.1.2
Homepage https://github.com/joalbright/Inlinit
License MIT
Platforms ios 9.0, requires ARC
Authors

A new design pattern to allow closure initialization.

Version
License
Platform

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 SwiftPM.

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.

Latest podspec

{
    "name": "Inlinit",
    "version": "0.1.2",
    "summary": "A new design pattern to allow closure initialization.",
    "description": "Reduces the need for unnecessary local variables. This also allows you to create let constants while appending values to it within the initalizer closure.",
    "homepage": "https://github.com/joalbright/Inlinit",
    "license": "MIT",
    "authors": {
        "Jo Albright": "[email protected]"
    },
    "source": {
        "git": "https://github.com/joalbright/Inlinit.git",
        "tag": "0.1.2"
    },
    "social_media_url": "https://twitter.com/joalbright",
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true,
    "source_files": "Sources/*",
    "resource_bundles": {
        "Inlinit": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This