Swift 解析创建用户

Swift Parse create a user

我是 swift 的新手,我很难弄清楚为什么 https://www.parse.com/docs/ios_guide#users/iOS 上的代码对我不起作用

var user = PFUser()
user.username = "myUsername"
user.password = "myPassword"
user.email = "email@example.com"
// other fields can be set just like with PFObject
user["phone"] = "415-392-0202"

user.signUpInBackgroundWithBlock {
(succeeded: Bool!, error: NSError!) -> Void in
  if error == nil {
    // Hooray! Let them use the app now.
  } else {
    let errorString = error.userInfo["error"] as NSString
    // Show the errorString somewhere and let the user try again.
  }
}

这一行

user.signUpInBackgroundWithBlock 

给我以下错误

Cannot invoke 'signUpInBackgroundWithBlock' with an argument list of type '((Bool!, NSError!) -> Void)'

我可以将 Objective-C 的代码复制并粘贴到我的项目中,它工作得很好,但是当我尝试对 Swift 代码执行相同操作时。我收到此错误消息。我还需要做些什么才能让它在 Swift 中正常工作吗?

我找到了解决方案,以防其他人遇到类似问题。下面的代码似乎工作正常。现在我只是想知道为什么 parse.com 在他们的文档中给出了上面的代码但实际上不起作用

user.signUpInBackgroundWithBlock {
    (succeeded: Bool, error: NSError?) -> Void in
    if error == nil {
        // Hooray! Let them use the app now.
    } else {
    }
}