【问题标题】:Swift Parse create a userSwift Parse 创建用户
【发布时间】:2015-04-25 00:58:36
【问题描述】:

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

【问题讨论】:

  • 你使用的是 swift 1.1 还是 1.2?如果您使用的是 Xcode 6.3+,那么您使用的是 1.2。 Parse 文档反映了 1.1。

标签: ios iphone swift parse-platform pfuser


【解决方案1】:

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

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

【讨论】:

  • 我认为问题是因为您使用的是 Swift 1.2
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-14
  • 2016-04-17
相关资源
最近更新 更多