Giter Club home page Giter Club logo

promisekit's Introduction

PromiseKit

badge-pod badge-languages badge-pms badge-platforms Build Status

繁體中文, 简体中文


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
    self.show(UIAlertController(for: 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. It is a top-100 pod used in many of the most popular apps in the world.

Quick Start

In your Podfile:

use_frameworks!

target "Change Me!" do
  pod "PromiseKit", "~> 4.4"
end

PromiseKit 4 and 5 support Xcode 8.1, 8.2, 8.3 and 9.0; Swift 3.0, 3.1, 3.2 and 4.0; iOS, macOS, tvOS, watchOS, Linux and Android; CocoaPods, Carthage and SwiftPM; (CI Matrix).

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

PromiseKit 5

PromiseKit 5 has been released, but is not yet fully documented, so we advise sticking with version 4 for the time being.

Documentation

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

Extensions

Promises are only as useful as the asynchronous tasks they represent, thus we have converted (almost) all of Apple’s APIs to promises. By default PromiseKit only provides promises, the extensions are available by specifying additional subspecs in your Podfile, eg:

pod "PromiseKit/MapKit"          # MKDirections().calculate().then { /*…*/ }
pod "PromiseKit/CoreLocation"    # CLLocationManager.requestLocation().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'
// https://github.com/PromiseKit/Alamofire
Alamofire.request("http://example.com", method: .post).responseJSON().then { json in
    //…
}.catch { error in
    //…
}

// pod 'PromiseKit/OMGHTTPURLRQ'
// https://github.com/PromiseKit/OMGHTTPURLRQ
URLSession.POST("http://example.com").asDictionary().then { json in
    //…
}.catch { error in
    //…
}

// pod 'PromiseKit/Foundation'
// https://github.com/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 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.

Support

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

promisekit's People

Contributors

mxcl avatar nathanhosselton avatar zlangley avatar filipzawada avatar tgaul avatar lammertw avatar josejulio avatar allen-zeng avatar codecaffeine avatar lutzifer avatar shergin avatar tikitu avatar ryanschneider avatar pgherveou avatar kdubb avatar javilorbada avatar feighter09 avatar abizern avatar cecuba avatar mortonfox avatar leomehlig avatar jacobwallstrom avatar djtarazona avatar danielt1263 avatar programmerdave avatar dbachrach avatar bruzenak avatar thaterikperson avatar vineetshah avatar victorg1991 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.