我在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'期待什么样的论点。
有谁知道如何解决这些问题?
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)
}
}