BoltsSwift 0.2.0

BoltsSwift 0.2.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2015
SPMSupports SPM

Maintained by Ken Van Hoeylandt.



  • By
  • Ken Van Hoeylandt

Bolts-Swift

This project primarily provides Swift support for the Bolts library for OS X and iOS.
It also provides extensions for existing iOS classes.

This project is dependent on the Bolts iOS project through Cocoapods.

Usage

Easily start Tasks in the background or on the main thread:

// Background thread task
BFTask.task(.Background, closure:
{
    (task: BFTask!) -> AnyObject! in
    return nil
})

// Main thread task
BFTask.task(.Main, closure:
{
    (task: BFTask!) -> AnyObject! in
    return nil
})

Easily continue tasks in the desired way:

  • onSuccessInBackground
  • onSuccessInMainThread
  • continueInBackground
  • continueInMainThread
findAsync()
  .onSuccessInBackground
  {
    (task: BFTask!) -> AnyObject! in

    // background data-processing
    let data = process(task.result)

    return data
  }
  .continueInMainThread
  {
    (task: BFTask!) -> AnyObject! in

    if (!task.faulted)
    {
          UIAlertView(title: "Result",
            message: "Task completed",
            delegate: nil,
            cancelButtonTitle: "OK").show()
    }
    else
    {
          UIAlertView(title: "Error",
            message: "Task failed",
            delegate: nil,
            cancelButtonTitle: "OK").show()
    }

    return nil
  }

Resolve image URLs in the background:

UIImage.imageAsync(url)
    .onSuccessInMainThread
    {
        (task: BFTask!) -> AnyObject! in

        var image = task.result as? UIImage

        return nil
    }

Or asynchronously load an image URL into a UIImageView:

imageView.setImageAsync(url)

Requirements

  • Swift 1.2
  • iOS 8 or OS X 10.9

Installation

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

pod 'BoltsSwift'

Author

Ken Van Hoeylandt, [email protected]

License

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