Swift Parse创建一个用户

时间:2015-04-25 00:58:37

标签: ios iphone swift parse-platform pfuser

我是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中正常工作吗?

1 个答案:

答案 0 :(得分:2)

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

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