0

我正在使用Swift iOS 应用程序,Parse并且PFUser发现自己处于PFUser.current()由于同步问题而不能完全按照我想要的方式执行的情况。

出于这个原因,我试图使用:PFUser.getCurrentUserInBackground()

我从下面的代码开始,灵感来自这里可以找到的内容:https ://github.com/BoltsFramework/Bolts-ObjC 。

但是这个文件可能有点过时了,它不太管用。

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.
    }
}

编译器给了我两个错误,这个在标记为“Error-1”的行上

Cannot invoke 'isCancelled' with no arguments

而这一行上的另一个标记为“Error-2”

Expression type 'PFUser?' is ambiguous without more context

我不知道“isCancelled”期待什么样的论点。

有谁知道如何解决这些问题?

4

1 回答 1

1
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)
    } 
}
于 2019-03-18T08:58:18.980 回答