marinehero / PromiseKit

Promises for Swift & ObjC

Home Page:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


badge-pod badge-languages badge-pms badge-platforms badge-mit

繁體中文, 简体中文

Promises simplify asynchronous programming, freeing you up to focus on the more important things. They are easy to learn, easy to master and result in clearer, more readable code. Your co-workers will thank you.

UIApplication.shared.isNetworkActivityIndicatorVisible = true

firstly {
    when(URLSession.dataTask(with: url).asImage(), CLLocationManager.promise())
}.then { image, location -> Void in
    self.imageView.image = image
    self.label.text = "\(location)"
}.always {
    UIApplication.shared.isNetworkActivityIndicatorVisible = false
}.catch { error in error), sender: self)

PromiseKit is a thoughtful and complete implementation of promises for any platform with a swiftc, it has excellent Objective-C bridging and delightful specializations for iOS, macOS, tvOS and watchOS.

Quick Start

In your Podfile:

swift_version = "3.1"
pod "PromiseKit", "~> 4.3"

PromiseKit 4 supports Xcode 8 and 9, Swift 3.0, 3.1, 3.2 and Swift 4.0.

For Carthage, SwiftPM, etc., or for instructions when using older Swifts or Xcodes see our Installation Guide.


If you are looking for a function’s documentation, then please note our sources are thoroughly documented.


Promises are only as useful as the asynchronous tasks they represent, thus we have converted (almost) all of Apple’s APIs to promises. The default CocoaPod comes with promises for UIKit and Foundation, the rest can be installed by specifying additional subspecs in your Podfile, eg:

pod "PromiseKit/MapKit"          # MKDirections().promise().then { /*…*/ }
pod "PromiseKit/CoreLocation"    # CLLocationManager.promise().then { /*…*/ }

All our extensions are separate repositories at the PromiseKit organization.

Choose Your Networking Library

Promise chains are commonly started with networking, thus we offer multiple options: Alamofire, OMGHTTPURLRQ and of course (vanilla) NSURLSession:

// pod 'PromiseKit/Alamofire'
Alamofire.request("", method: .post).responseJSON().then { json in
}.catch { error in

// pod 'PromiseKit/OMGHTTPURLRQ'
URLSession.POST("").asDictionary().then { json in
}.catch { error in

// pod 'PromiseKit/Foundation'
URLSession.shared.dataTask(url).asDictionary().then { json in
}.catch { error in

Nobody ever got fired for using Alamofire, but at the end of the day, it’s just a small wrapper around NSURLSession. OMGHTTPURLRQ supplements NSURLRequest to make generating REST style requests easier, and the PromiseKit extensions extend NSURLSession to make OMG usage more convenient. But since a while now most servers accept JSON, so writing a simple API class that uses vanilla NSURLSession and our promises is not hard, and gives you the most control with the fewest black-boxes.

The choice is yours.


Ask your question at our Gitter chat channel or on our bug tracker.


Promises for Swift & ObjC

License:MIT License


Language:Swift 65.4%Language:Objective-C 31.7%Language:Ruby 2.9%