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
6
votes
1 answer

How to wait on multiple PromiseKit promises which have a different payload?

In my project, I have numerous functions which asynchronously fetch data from the underlying data source and return result as a Promise, where T is an optional model object. I need to fetch 2 different, independent objects in parallel. For that…
Serzhas
  • 854
  • 12
  • 23
6
votes
2 answers

What happens to a promise that's abandoned?

I have the following code defined in a view controller. _ = accountService.getAccount() .then { user -> Void in self.txtBxUser.text = user.username self.txtBxEmail.text = user.email } getAccount makes a REST API…
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
6
votes
1 answer

Unit Test function that uses PromiseKit

I have the following function which I want to test: func getProduct(ean: String) -> Promise { return Promise { fullfill, reject in let urlString = BSConstants.BarcodeScanner.productEndpoint.stringByAppendingString(ean) …
Hodson
  • 3,438
  • 1
  • 23
  • 51
6
votes
2 answers

How to fulfill nil promise swift

I want to fulfill a promise with nil but I get error message that I cant here is my code public static func getCurrentDevice() -> Promise{ if let identity:[String:AnyObject] = auth?.get("identity") as! [String:AnyObject] { if let…
Cesar Oyarzun
  • 169
  • 2
  • 8
5
votes
1 answer

What does it mean in Swift: 'case .success(let dict):'

In Swift PromiseKit library there's Alamofire example using a bit strange syntax: func login(completionHandler: (NSDictionary?, ErrorProtocol?) -> Void { Alamofire.request(.GET, url, parameters: ["foo": "bar"]) .validate() …
konrad
  • 1,664
  • 2
  • 17
  • 36
5
votes
1 answer

Convert from one promise type to another

If I have one function which returns a promise and calls another function which also returns a promise, is it possible to convert between the two without doing this... func f1() -> Promise { ... } func f2() -> Promise { return…
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
5
votes
1 answer

Objc PromiseKit: Add new promises from within a promise

I'm using PromiseKit to simply my API requests. In this scenario, I'm fetching a list of objects IDs from the server. I need to then fetch details for each ID, and return an array of details. Fairly common scenario. Effectively, I need to add…
emma ray
  • 13,336
  • 1
  • 24
  • 50
4
votes
2 answers

PromiseKit 6.0 passing catched errors to caller

According to migration guide PromiseKit 6.x changed his policy about catch blocks. In PMK 4 catch returned the promise it was attached to. Now catch is a chain- terminator. I understand why these changes were made but... In my codebase (connected…
Kamil Harasimowicz
  • 4,684
  • 5
  • 32
  • 58
4
votes
4 answers

Swift4 Error Cannot convert value of type '(_) -> Void' to expected argument type '(_) -> _'

Using PromiseKit for API call in Swift 4: let apiCall = ApiManager.shared.fetchActors() apiCall.then { actors -> Void in self.dataSourceArray = actors self.tableView.reloadData() }.catch { error -> Void in } I…
nhuluseda
  • 637
  • 3
  • 8
  • 19
4
votes
1 answer

PromiseKit fulfill and reject convention

I'm using PromiseKit to handle my network calls. I'm trying to see if there's a convention or a cleaner way to either fulfill or reject the promise early. As illustrated below, there are a few conditions that would require me to fulfill or reject…
7ball
  • 2,183
  • 4
  • 26
  • 61
4
votes
1 answer

What does Void() in Swift 4 mean in PromiseKit?

What does Void in Swift 4 mean? If I have a function to fulfill, as follows: func someFunc() -> Promise { fulfill() } an error shows, and it only works if: fulfill(Void()) Note. Swift 3 supported: fulfill() I am using Swift 4, but can…
lePapa
  • 357
  • 2
  • 11
4
votes
1 answer

How to pass data across down a promise chain?

Let's say that I want to generate a data set that requires multiple promises to resolve, how would I store each result down the promise chain so I can create my final data set in one shot? struct CompleteData { let a: String let b:…
ldiqual
  • 15,015
  • 6
  • 52
  • 90
4
votes
1 answer

How can I chain promises in Swift inside a loop?

I'm building a Swift-based iOS application that uses PromiseKit to handle promises (although I'm open to switching promise library if it makes my problem easier to solve). There's a section of code designed to handle questions about overwriting…
Andrew Ferrier
  • 16,664
  • 13
  • 47
  • 76
4
votes
2 answers

Why must I return a promise?

Here is the code... login().then { // our login method wrapped an async task in a promise return API.fetchKittens() }.then { fetchedKittens in // our API class wraps our API and returns promises // fetchKittens returned a promise…
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
3
votes
1 answer

What is the Swift concurrency equivalent to a promise–resolver pair?

With the PromiseKit library, it’s possible to create a promise and a resolver function together and store them on an instance of a class: class ExampleClass { // Promise and resolver for the top news headline, as obtained from // some web…
bdesham
  • 15,430
  • 13
  • 79
  • 123
1
2
3
16 17