Latest 1.1.0
Homepage https://github.com/hb1love/Scope
License MIT
Platforms ios 8.0, requires ARC
Authors

Build Status
Platform
Swift
CocoaPods
Carthage compatible

🌷 Scoping Functions of Kotlin Style for Readable Code

Usage

also, with, let, run, apply

Initialize Instance with also in closure

let org = Organazation().also {
    $0.name = "podo"
    $0.member = Member(name: "hb1love", role: .owner)
}

Similarly, we can be used like this. with

with(organization.member) {
    $0.name = "podo"
    $0.role = .owner
}

Imagine if organization.member could be null, maybe it looks like this: Use let !

// so bad..
with(organization.member) {
    $0?.name = "hb1love"
    $0?.role = .owner
}

// Good!
org.member?.let {
    $0.name = "hb1love"
    $0.role = .owner
}

it is fully enclosed within the run scope.

var age = 17
run {
    var age = 27
    print(age) // 27
}
print(age) // 17
let org = run { () -> Organazation in
    someFunc1()
    someFunc2()
    someFunc3()
    return Organazation(name: "podo")
}

Use apply, when you need any logic after initialization

let org = Organazation().apply {
    someFunc1()
    someFunc2()
}

apply has no parameters. It just returns an instance.

Requirements

  • iOS 8.0+
  • Xcode 9.0+
  • Swift 3.0+

Installation

pod 'Scope'
github "hb1love/Scope"

License

Scope is available under the MIT license. See the LICENSE for details.

Latest podspec

{
    "name": "Scope",
    "version": "1.1.0",
    "summary": "ud83cudf37 Scoping Functions of Kotlin Style for Readable Code",
    "homepage": "https://github.com/hb1love/Scope",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Kim Heebeom": "[email protected]"
    },
    "social_media_url": "http://happytiger.co.kr",
    "source": {
        "git": "https://github.com/hb1love/Scope.git",
        "tag": "1.1.0"
    },
    "source_files": "Scope/Classes/**/*",
    "requires_arc": true,
    "platforms": {
        "ios": "8.0"
    }
}

Pin It on Pinterest

Share This