
现在,使用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) } } })}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)