Carl
Carl

Reputation: 2934

Example of using Task.all

I'm using swifttask but I need an example of how to use Task.all()

I have:

let t1 = Task<String, PFObject, NSError> {
    progress, fulfill, reject, configure in
    let (obj, error) = getPFObject() // placeholder for my code
    if ... {
        fulfill(obj)
    } else {
        reject(error)
    }
}

let t2 = Task<String, [PFObject], NSError> {
    ... code to retrieve array of PFObject
    ... fulfill or reject
}

Task.all([t1,t2]).progress {
    oldProgress, newProgress in
    println("When is this line executed?")
}.success { value -> Void in
    println("Done successfully")
}.failure { ... in
    println(errorInfo)
}

How do I declare following failure{ ... and when do "When is this line executed" output?

Upvotes: 2

Views: 222

Answers (1)

Carl
Carl

Reputation: 2934

The problem was my definition of t1 and t2.

In Swift/SwiftTask they have to be the same. Change t1 to:

let t1 = Task<String, [PFObject], NSError> {

so that it too, like t2, deals in arrays of PFObject. This removed the Xcode error about .failure.

Upvotes: 1

Related Questions