Questions tagged [promisekit]

PromiseKit is Objective-C and Swift Promises implementation. It is also a collection of helper functions that make the typical asynchronous patterns we use in iOS development delightful too.

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

PromisesKit is not just a Promises implementation, it is also a collection of helper functions that make the typical asynchronous patterns we use in iOS development delightful too.

In addition, PromisesKit is designed to be integrated into other CocoaPods. If your library has asynchronous operations then consider adding an opt-in subspec that provides Promises for your users. Documentation to help you integrate PromiseKit into your own pods is provided later in this guide.

PromisesKit is available in Objective-C and Swift flavors.

241 questions
53
votes
7 answers

Chain multiple Alamofire requests

I'm looking for a good pattern with which I can chain multiple HTTP requests. I want to use Swift, and preferrably Alamofire. Say, for example, I want to do the following: Make a PUT request Make a GET request Reload table with data It seems that…
jlhonora
  • 10,179
  • 10
  • 46
  • 70
21
votes
1 answer

Create a new NSError in Swift (to reject a Promise from PromiseKit)

I have been trying to use PromiseKit, and I'm stuck at rejecting a promise. Promise rejection is done either by calling a reject function with an NSError as argument. func getAPromise() -> Promise { return Promise { fulfiller,…
AsTeR
  • 7,247
  • 14
  • 60
  • 99
17
votes
2 answers

Should I use [weak self] in PromiseKit blocks?

PromiseKit states the following on their website: Should I be concerned about retain cycles? tl;dr: it’s safe to use self in promise handlers. This is safe: somePromise.then { self.doSomething() } Provided somePromise resolves, the function…
Senseful
  • 86,719
  • 67
  • 308
  • 465
11
votes
3 answers

PromiseKit 6.13.1 cannot conform to 'Thenable' when I try to use Promise functions

I am finding extremely hard to use PromiseKit 6.13.1 in an apparently simple situation. I have the following two functions returning a Promise but I cannot seem to find a way to use them with ```firstly{}.then{} syntax: func…
Fabrizio Prosperi
  • 1,398
  • 4
  • 18
  • 32
10
votes
4 answers

PromiseKit with Swift: terminate chain of promises

I'm trying to use PromiseKit with Swift. I am not really familiar with it, and there doesn't seem to be much information on its usage with Swift. I can't seem to figure out how to terminate a chain of promises. As long as the last (terminal) then…
Andrii Chernenko
  • 9,873
  • 7
  • 71
  • 89
9
votes
1 answer

Returning void in PromiseKit 6

This is what I had working with PromiseKit 4.5 api.getUserFirstName().then { name -> Void in print(name) } getUserFirstName() returns a Promsise. I updated to PromiseKit 6 and this now throws an error: Cannot convert value of type '(_) ->…
7ball
  • 2,183
  • 4
  • 26
  • 61
9
votes
2 answers

Swift PromiseKit: Equivalent to when() which executes sequentially?

I'm using PromiseKit with Swift, which has been very handy so far. One of the functions they provide is when(), which allows you to have an array of any number of promises and execute something only once ALL of them have completed. However, the…
derf26
  • 862
  • 1
  • 7
  • 16
9
votes
3 answers

PromiseKit cancel a promise

How do I cancel a promise that has been neither fulfilled or rejected yet? The documentation for PromiseKit talks about cancelling a promise, but I can't find a specific example of how to do this. Given: currentOperation = client.load(skip: skip,…
Jasper Blues
  • 28,258
  • 22
  • 102
  • 185
8
votes
2 answers

Can't return a promise chain with a catch block on the end

This used to work but with version 6 of PromiseKit this... func checkIn(request: CheckinRequest) -> Promise { let p = checkinService.checkIn(request: request) .then { r -> Promise in return…
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
8
votes
1 answer

error: cannot convert value of type '() -> ()' to closure result type 'String' using Swift + PromiseKit

I am new to promises in Swift and using PromiseKit to try and create a very simple response in a playground and attempt to use it. I have the following code: import UIKit import PromiseKit func foo(_ error: Bool) -> Promise { return…
John Mike
  • 1,895
  • 3
  • 17
  • 26
8
votes
3 answers

Using PromiseKit to force sequential download

I am using PromiseKit and would like to force sequential download of JSONs. The count of JSONs might change. I have read this about chaining. If I had a fixed number of say 3 downloads, this would be fine. But what if I had a changing count of…
brainray
  • 12,512
  • 11
  • 67
  • 116
7
votes
1 answer

Swift async/await equivalent of Promise Kit "when" pattern

I'm new to Swift, coming from JS, and I've started to build an iOS app. Initially I went down the road, using Promise Kit for the async stuff, as it seemed easier to me than other things I read about. Regardless, in JS, I use the following pattern a…
Kim
  • 856
  • 1
  • 11
  • 21
7
votes
1 answer

Swift 3.0: Unable to infer closure type in the current context ,PromiseKit

I have following code in swift 3.0, Where I am using PromiseKit. func calculateTravelTime(from: CLLocation, to: CLLocation) -> Promise { Promise { completion, reject -> Void in let request = MKDirections.Request() …
PlusInfosys
  • 3,416
  • 1
  • 19
  • 33
7
votes
1 answer

How to use swift-4 Promises then, done, catch and other blocks

I would like to learn about promises in swift-4. How to use multiple then statements and done, catch blocks. Here I am trying to get the value from the promise. But I'm getting errors. Could someone help me to understand promises? Here is my code.…
Damodar
  • 707
  • 2
  • 10
  • 23
7
votes
1 answer

Swift & PromiseKit: Resolving ALL promises from a loop

I'm looking for a solution in Swift3 to resolve a dynamic number of promises all at once, e.g. like this sample in JavaScript: var promises = []; for(var i = 0; i < 5; i++) { var promise = $http.get('/data' + i); …
Thread Pitt
  • 716
  • 1
  • 6
  • 20
1
2 3
16 17