Git Product home page Git Product logo

promisekit's Introduction

PromiseKit

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

Modern development is highly asynchronous: isn’t it about time we had tools that made programming asynchronously powerful, easy and delightful?

UIApplication.sharedApplication().networkActivityIndicatorVisible = true

firstly {
    when(NSURLSession.GET(url).asImage(), CLLocationManager.promise())
}.then { image, location -> Void in
    self.imageView.image = image
    self.label.text = "\(location)"
}.always {
    UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}.error { error in
    UIAlertView(/*…*/).show()
}

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

# CocoaPods
pod "PromiseKit", "~> 3.4"

# Carthage
github "mxcl/PromiseKit" ~> 3.4

# SwiftPM
let package = Package(
    dependencies: [
        .Package(url: "https://github.com/mxcl/PromiseKit", majorVersion: 4)
    ]
)

Alternatively, drop PromiseKit.xcodeproj into your project and add PromiseKit.framework to your app’s embedded frameworks.

Documentation

We have thorough and complete documentation at promisekit.org.

Overview

Promises are defined by the function then:

login().then { json in
    //…
}

They are chainable:

login().then { json -> Promise<UIImage> in
    return fetchAvatar(json["username"])
}.then { avatarImage in
    self.imageView.image = avatarImage
}

Errors cascade through chains:

login().then {
    return fetchAvatar()
}.then { avatarImage in
    //…
}.catch { error in
    UIAlertView(/*…*/).show()
}

They are composable:

let username = login().then{ $0["username"] }

when(username, CLLocationManager.promise()).then { user, location in
    return fetchAvatar(user, location: location)
}.then { image in
    //…
}

They are trivial to refactor:

func avatar() -> Promise<UIImage> {
    let username = login().then{ $0["username"] }

    return when(username, CLLocationManager.promise()).then { user, location in
        return fetchAvatar(user, location: location)
    }
}

Continue Learning…

Complete and progressive learning guide at promisekit.org.

PromiseKit vs. Xcode

PromiseKit contains Swift, so we engage in an unending battle with Xcode:

Xcode Swift PromiseKit CI Status Release Notes
8 3.0 4 ci-swift3 Pending
8 2.3 3 ci-master 2015/10
7 2.2 3 ci-master 2015/10
6 1.2 2 2015/05
* N/A 1† ci-legacy

† PromiseKit 1 is pure Objective-C and thus can be used with any Xcode, it is also your only choice if you need to support iOS 7 or below.


We maintain some branches to aid migrating between Swift versions:

Xcode Swift PromiseKit Branch CI Status
8.0 2.3 2 swift-2.3-minimal-changes ci-23
7.3 2.2 2 swift-2.2-minimal-changes ci-22
7.2 2.2 2 swift-2.2-minimal-changes ci-22
7.1 2.1 2 swift-2.0-minimal-changes ci-20
7.0 2.0 2 swift-2.0-minimal-changes ci-20

We do not backport fixes (mostly) to these migration-branches, but pull-requests are welcome.

Support

promisekit's People

Contributors

mxcl avatar nathanhosselton avatar tgaul avatar codecaffeine avatar allen-zeng avatar josejulio avatar lammertw avatar abizern avatar feighter09 avatar kdubb avatar pgherveou avatar tikitu avatar shergin avatar lutzifer avatar leomehlig avatar jacobwallstrom avatar thaterikperson avatar bruzenak avatar dbachrach avatar programmerdave avatar danielt1263 avatar djtarazona avatar weiran avatar korzonek avatar tcunning avatar tp avatar stevenp avatar slavikus avatar sdolidze avatar ryanschneider avatar

Watchers

Trevor Sheridan 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.