Latest 1.0.1
Homepage https://github.com/xxxAIRINxxx/Fly
License MIT
Platforms ios 8.0, requires ARC
Authors

Swift 2.1+
Platforms iOS
Xcode 7.1+

Fly is inspired by Async.

Features

  • Execution control of chained closures (next, cancel, complete, error, back, retry, restart).
  • Can select the executed queue of GCD (Grand Central Dispatch).
  • Pass the object to the next queue.
  • Less code indentation.

Exsamples

Basics

Fly.onFirst { result in
    // called first
    // called at main thread queue

    print("Basics onFirst")
    print(result)
    let count = (result as! Int)
    return FlyResult.Next(result: count + 1)
    }.onNext(GCD.Background) { result in
        // called second
        // called at background qos class thread queue

        print("Basics onNext1")
        print(result)
        let count = (result as! Int)
        return FlyResult.Next(result: count + 1)
    }.onNext(GCD.Default) { result in
        // called third
        // called at default qos class thread queue

        print("Basics onNext2")
        print(result)
        if (result as! Int) > 10 {
            // call complete closure
            return FlyResult.Finish(result: result)
        } else {
            // call cancel closure
            return FlyResult.Cancel
        }
    }.onCancel(GCD.Utility) {
        // called fourth
        // called at utility qos class thread queue

        print("Basics cancel")
    }.onComplete { result in
        // called last
        // called at main thread queue

        print("Basics completion")
        print(result)
    }.fly(0)
}

Retry

Fly.onFirst { result in
    // called first

    print("Retry onFirst")
    print(result)
    let count = (result as! Int)
    return FlyResult.Next(result: conut)
    }.onNext(GCD.Default) { result in
        // called second

        print("Retry onNext")
        print(result)
        let count = (result as! Int)
        if count > 10 {
            // call complete
            return FlyResult.Finish(result: conut)
        } else {
            // call this closure
            return FlyResult.Retry(result: count + 1)
        }
    }.onComplete(GCD.Background) { result in
        // called last

        print("Retry completion")
        print(result)
    }.fly(0)

Back


Fly.onFirst { result in
    // called first

    print("Back onFirst")
    print(result)
    let count = (result as! Int)
    return FlyResult.Next(result: count + 1)
    }.onNext(GCD.Background) { result in
        // called second

        print("Back onNext1")
        print(result)
        let count = (result as! Int)
        return FlyResult.Next(result: count + 1)
    }.onNext(GCD.Default) { result in
        // called third

        print("Back onNext2")
        print(result)
        if (result as! Int) > 10 {
            // call complete closure
            return FlyResult.Finish(result: result)
        } else {
            // call previous closure
            return FlyResult.Back(result: result)
        }
    }.onComplete(GCD.Background) { result in
        // called last

        print("Back completion")
        print(result)
    }.fly(0)
}

Restart

Fly.onFirst { result in
    // called first

    print("Restart onFirst")
    print(result)
    let count = (result as! Int)
    return FlyResult.Next(result: count + 1)
    }.onNext(GCD.Background) { result in
        // called second

        print("Restart onNext1")
        print(result)
        let count = (result as! Int)
        return FlyResult.Next(result: count + 1)
    }.onNext(GCD.Default) { result in
        // called third

        print("Restart onNext2")
        print(result)
        if (result as! Int) > 10 {
            // call complete closure
            return FlyResult.Finish(result: result)
        } else {
            // call first closure
            return FlyResult.Restart(result: result)
        }
    }.onComplete(GCD.Background) { result in
        // called last

        print("Restart completion")
        print(result)
    }.fly(0)

Requirements

  • Xcode 7.1+
  • iOS 8.0+
  • Swift 2.1+

Installation

CocoaPods

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

use_frameworks!

pod "Fly"

Carthage

To integrate Chain into your Xcode project using Carthage, specify it in your Cartfile:

github "xxxAIRINxxx/Fly"

License

MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Fly",
    "version": "1.0.1",
    "summary": "Execution control of chained closures (next, cancel, complete, error, back, retry, restart).",
    "homepage": "https://github.com/xxxAIRINxxx/Fly",
    "license": "MIT",
    "authors": {
        "Airin": "[email protected]"
    },
    "source": {
        "git": "https://github.com/xxxAIRINxxx/Fly.git",
        "tag": "1.0.1"
    },
    "requires_arc": true,
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Sources/*.swift"
}

Pin It on Pinterest

Share This