使用PFUser.getCurrentUserInBackground()的错误

问题描述 投票:0回答:1

我在Swift iOS应用程序中使用ParsePFUser,并发现自己处于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'期待什么样的论点。

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

ios swift parse-platform pfuser parse-ios-sdk
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)
    } 
}
© www.soinside.com 2019 - 2024. All rights reserved.