Available thruCocoapods
Latest1.0.4
Homepagehttps://github.com/khoiln/RunKit
LicenseMIT

RunKit
CocoaPods compatible
Carthage compatible
RunKit
RunKit
RunKit

A Swift Wrapper for libdispatch aka Grand Central Dispatch (GCD) Framework that supports method chaining.

Tired of this?

dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)) { () -> Void in
    for index in 1...UInt64.max{
        print(index)
    }
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
        print("Back to main thread")
    })
}

With RunKit

Run.background { 
    for index in 1...UInt64.max{
        print(index)
    }
}.main { 
    print("Back to main thread")
}

Installation

Cocoapods

Add this to your Podfile

pod 'RunKit', '~> 1.0'

Carthage

Add this to your Cartfile

github "khoiln/RunKit"

Usage

Supported Queues:

Run.main {}
Run.userInteractive {}
Run.userInitiated {}
Run.utility {}
Run.background {}

Queues Chaining:

Run.main { 
    print("main queue")
}.background { 
    print("background queue")
}.userInitiated {
    print("userInitiated queue")
}.main { 
    print("Back to main thread")
}

Using Custom Queue:

let queue = dispatch_queue_create("queue1", DISPATCH_QUEUE_SERIAL)
Run.custom(queue: queue){
    print("User created Queue")
}

Store blocks reference for chaining

let longRunningBlock = Run.background{
    for index in 1...UInt64.max{
        print(index)
    }
}
longRunningBlock.main{
    print("Back to main thread")
}

You can also cancel a running process

longRunningBlock.cancel()

Or wait for it to finish

longRunningBlock.wait()
print("Continue..")

License

RunKit is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "RunKit",
    "version": "1.0.4",
    "summary": "A Swift Wrapper for Grand Central Dispatch (GCD) Framework that supports method chaining",
    "homepage": "https://github.com/khoiln/RunKit",
    "license": {
        "type": "MIT"
    },
    "authors": {
        "Khoi": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "source": {
        "git": "https://github.com/khoiln/RunKit.git",
        "tag": "1.0.4"
    },
    "source_files": "Source/**/*.{swift,h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This