解析和Swift 1.2问题

解析和Swift 1.2问题,第1张

解析和Swift 1.2问题

现在,使用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) }        }    })}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4930234.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存