Swiftpack.co - Package - mxcl/PromiseKit

PromiseKit

badge-pod badge-languages badge-pms badge-platforms badge-travis


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

let fetchImage = URLSession.shared.dataTask(.promise, with: url).compactMap{ UIImage(data: $0.data) }
let fetchLocation = CLLocationManager.requestLocation().lastValue

firstly {
    when(fulfilled: fetchImage, fetchLocation)
}.done { image, location in
    self.imageView.image = image
    self.label.text = "\(location)"
}.ensure {
    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 that has 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.

codecov

PromiseKit 7 Alpha

We are testing PromiseKit 7 alpha, it is Swift 5 only. It is tagged and thus importable in all package managers.

PromiseKit 6

Release notes and migration guide.

Quick Start

In your Podfile:

use_frameworks!

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

The above gives an Xcode warning? See our Installation Guide.

PromiseKit 6, 5 and 4 support Xcode 8.3, 9.x and 10.0; Swift 3.1, 3.2, 3.3, 3.4, 4.0, 4.1, 4.2, 4.3 and 5.0 (development snapshots); iOS, macOS, tvOS, watchOS, Linux and Android; CocoaPods, Carthage and SwiftPM; (CI Matrix).

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

Professionally Supported PromiseKit is Now Available

TideLift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.

Get Professional Support for PromiseKit with TideLift.

PromiseKit is Thousands of Hours of Work

Hey there, I’m Max Howell. I’m a prolific producer of open source software and probably you already use some of it (I created brew). I work full-time on open source and it’s hard; currently I earn less than minimum wage. Please help me continue my work, I appreciate it 🙏🏻

Other ways to say thanks.

Documentation

Extensions

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 provides Promises and the extensions for Foundation and UIKit. The other extensions are available by specifying additional subspecs in your Podfile, e.g.:

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

All our extensions are separate repositories at the PromiseKit organization.

I don't want the extensions!

Then don’t have them:

pod "PromiseKit/CorePromise", "~> 6.8"

Note: Carthage installations come with no extensions by default.

Choose Your Networking Library

Promise chains commonly start with a network operation. Thus, we offer extensions for URLSession:

// pod 'PromiseKit/Foundation'  # https://github.com/PromiseKit/Foundation

firstly {
    URLSession.shared.dataTask(.promise, with: try makeUrlRequest()).validate()
    // ^^ we provide `.validate()` so that eg. 404s get converted to errors
}.map {
    try JSONDecoder().decode(Foo.self, with: $0.data)
}.done { foo in
    //…
}.catch { error in
    //…
}

func makeUrlRequest() throws -> URLRequest {
    var rq = URLRequest(url: url)
    rq.httpMethod = "POST"
    rq.addValue("application/json", forHTTPHeaderField: "Content-Type")
    rq.addValue("application/json", forHTTPHeaderField: "Accept")
    rq.httpBody = try JSONEncoder().encode(obj)
    return rq
}

And Alamofire:

// pod 'PromiseKit/Alamofire'  # https://github.com/PromiseKit/Alamofire-

firstly {
    Alamofire
        .request("http://example.com", method: .post, parameters: params)
        .responseDecodable(Foo.self)
}.done { foo in
    //…
}.catch { error in
    //…
}

Nowadays, considering that:

  • We almost always POST JSON
  • We now have JSONDecoder
  • PromiseKit now has map and other functional primitives
  • PromiseKit (like Alamofire, but not raw-URLSession) also defaults to having callbacks go to the main thread

We recommend vanilla URLSession. It uses fewer black boxes and sticks closer to the metal. Alamofire was essential until the three bullet points above became true, but nowadays it isn’t really necessary.

Support

Please check our Troubleshooting Guide, and if after that you still have a question, ask at our Gitter chat channel or on our bug tracker.

Security & Vulnerability Reporting or Disclosure

https://tidelift.com/security

Github

link
Stars: 12394

Dependencies

Used By

Total: 0

Releases

6.13.0 - 2020-01-15 22:02:57

  • Added Keypath map etc. variants for Swift < 5.2

6.8.5 - 2019-06-28 14:24:03

Minor fixes for Xcode 10.2 in a few extensions.

6.10.0 - 2019-06-28 14:23:51

AnyPromise gains wait

6.9.0 - 2019-06-18 11:58:00

  • Guarantee gains thenMap, mapValues, etc. the same as Promise

7.0.0-alpha3 - 2019-04-12 02:17:42

6.8.4 - 2019-03-26 02:46:02

Fixes compile on Linux with Swift 5.

7.0.0-alpha2 - 2019-03-24 13:57:20

7.0.0-alpha1 - 2019-03-19 02:11:18

6.8.3 - 2019-02-01 21:59:39

  • Swift 5 support for SwiftPM

- 2019-02-01 19:57:57

- 2019-02-01 19:57:47

Updates the submodule for PromiseKit/EventKit to v4.

6.8.2 - 2019-02-01 19:57:35

Fixes spurious logging of pending guarantee deallocated.

6.8.0 - 2019-01-23 23:05:52

Important revocation of #963 due to semantic version breakage.

The change was useful but caused ambiguity with Swift for certain usage.

See #990 for details.

- 2018-12-04 23:54:39

Added logging control, see FAQ.

- 2018-10-10 22:04:57

  • Source breaking change for Process.PMKError
  • Fixes for Foundation/StoreKit

HealthKit extension added - 2018-10-03 22:46:52

- 2018-09-23 09:34:29

- 2018-08-22 15:49:37

Xcode 10 / Swift 4.2 support across all extensions.

- 2018-06-05 01:53:09

Updates to CloudKit extension deployment targets to avoid warnings on newer platforms.

If you need older deployments, you will have to vendor the older versions of these files.

- 2018-05-24 19:10:13

  • Lightweight ObjC generics

- 2018-05-24 19:09:57

  • Support for static libraries and CocoaPods

- 2018-05-15 21:05:19

- 2018-03-28 15:54:13

6.2.3: Added omitted `PMKRace` to `.podspec` - 2018-03-28 15:54:02

- 2018-03-04 18:20:53

  • Alamofire — Support Custom Serializers (PromiseKit/Alamofire@33c652a9b1b6a3a2f0eb06d082ec312682350e59)
  • Alamofire — Extended responseDecodable for JSONDecoder injection (PromiseKit/Alamofire@ddf0e15793970e538722f9b20737d196f6da6c35)

6.2.0 - 2018-02-28 19:42:03

We removed the deprecations for flatMap and map since it caused ambiguity.

1.7.6 - 2018-02-22 16:31:14

6.1.0; functional functions renamed - 2018-02-19 21:46:57

http://promisekit.org/news/2018/02/PromiseKit-6.0-Released/

6.0.3 - 2018-02-18 16:53:06

http://promisekit.org/news/2018/02/PromiseKit-6.0-Released/

- 2018-02-17 18:45:05

http://promisekit.org/news/2018/02/PromiseKit-6.0-Released/