2

I'm new to PromiseKit and I'm a bit confused to how to handle multiple promises. I'm using CloudKit and saving two records, and when they are both saved, I want to do something on completion and something else on error. I thought I should do the following, but Xcode is complaining so obviously I must have misunderstood:

let savePromise1 : PMKPromise = db.saveRecord(record1)
let savePromise2 : PMKPromise = db.saveRecord(record2)

PMKPromise.when([ savePromise1, savePromise2 ]).then() { results in
    // handle success or errors
}

The error I get is "Cannot convert the experssion's type '(($T8) -> ($T8) -> $T7) -> (($T8) -> ($T7) -> $T7' to type 'PMKPromise'

I don't really understand what the error means, but I was expecting "results" to be an array of (result, error) tuples.

How should I write my "when" statement instead?

Cheers

Nik

niklassaers
  • 8,480
  • 20
  • 99
  • 146
  • Are you using the Swift version or the Objective-C version of PromiseKit? – Michael Gaylord Sep 18 '14 at 13:50
  • I was using the Pod, so the ObjC version. The Swift version didn't have the CloudKit classes. I have since heard from the developer that this problem is not solved yet, but he's working on it. So for now, no solution, but hopefully soon. :-) I'd still love some input on how to read that expression type, though :-) – niklassaers Sep 19 '14 at 07:10

1 Answers1

1

Use the Swift version of PromiseKit, it now has CloudKit support:

when(db.save(record1), db.save(record2)).then { (record1, record2)->Void in

}

The Swift version also has a tuple-when so you don't have to sort through an array of results.

mxcl
  • 26,392
  • 12
  • 99
  • 98