Michel
Michel

Reputation: 11749

Errors using PFUser.getCurrentUserInBackground()

I am using Parse and PFUser in a Swift iOS app, and find myself in a case where PFUser.current() does not do exactly what I want, due to synchronisation issues.

For that reason I am trying to use: PFUser.getCurrentUserInBackground().

I got started with the code below, inspired from what can be found here: https://github.com/BoltsFramework/Bolts-ObjC.

But this document probably being a bit outdated, it does not quite work.

let userCheckTask = PFUser.getCurrentUserInBackground()
userCheckTask.continueWith {
    (task: BFTask!) -> BFTask<AnyObject> in
    if task.isCancelled() { // Error-1.
        // the save was cancelled.
    } else if task.error != nil {
        // the save failed.
    } else {
        // the object was saved successfully.
        var object = task.result() as PFObject // Error-2.
    }
}

The compiler gives me two errors, this one on the line marked "Error-1"

Cannot invoke 'isCancelled' with no arguments

And this other one on the line marked "Error-2"

Expression type 'PFUser?' is ambiguous without more context

I have no idea what kind of argument 'isCancelled' is expecting.

Does anyone know how to fix those?

Upvotes: 0

Views: 140

Answers (1)

Sachin Vas
Sachin Vas

Reputation: 1767

let userCheckTask = PFUser.getCurrentUserInBackground()
userCheckTask.continueWith {
    (task: BFTask) -> BFTask<AnyObject> in
    if let e = task.error {
        return BFTask(error: e)
    } else {
        return BFTask(result: task.result)
    } 
}

Upvotes: 1

Related Questions