@IBAction func load_click(sender: AnyObject) { var query = PFquery(classname: "myClass") query.getobjectInBackgrounDWithID("MPSVivtvJR",block: { (object:PFObject!,error: NSError) -> VoID in let thename = object["name"] as String let theAge = object["age"] as Int? println(thename) println(theAge) })}
它给了我错误:无法使用类型'(String,block:(PFObject!,NSError) – > VoID)的参数列表调用’GetobjectInBackgrounDWithID’
有任何想法吗?谢谢!
现在使用Swift 1.2,你应该更加小心打开选项.因此,在具有PFObject和NSError的闭包内,要么删除感叹号,要么添加问号以使其成为可选项.然后,更安全地打开您的物体.尝试如下:
// You can create this in a separate file where you save your modelsstruct myUser { let name: String? let age: Int?}// Now this in the vIEw controller@IBAction func load_click(sender: AnyObject) { var query = PFquery(classname: "myClass") query.getobjectInBackgrounDWithID("MPSVivtvJR",block: { (object:PFObject!,error: NSError?) -> VoID in if let thisname = object["name"] as? String{ if let thisAge = object["age"] as? Int{ let user = myUser(name: thisname,age: thisAge) println(user) } } })}总结
以上是内存溢出为你收集整理的parse.com – Parse和Swift 1.2问题全部内容,希望文章能够帮你解决parse.com – Parse和Swift 1.2问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)