访问Swift词典的可选值

时间:2014-09-10 07:55:02

标签: cocoa cocoa-touch dictionary swift

我将从JSON解析的字典定义为[String:AnyObject]

然后我尝试访问它的值;

var vote: Int?

if let voteValue: AnyObject = dictionary["vote"] {
    self.vote = voteValue as? Int
}

有更简单/更清洁的方法吗?

1 个答案:

答案 0 :(得分:1)

只能想到:

var vote: Int?
vote = dictionary["vote"] as AnyObject? as? Int