检查Swift中的任意对象值

检查Swift中的任意对象值,swift,Swift,使用以下代码: let decoded = NSJSONSerialization.JSONObjectWithData(data as! NSData, options: NSJSONReadingOptions.MutableContainers, error: nil) as! [String:AnyObject] 我得到了[纬度:40.3654922,韩元:1,经度:49.9384457,温尼里德:552e] 现在我想检查对象是否等于“1”,并执行一些操作。但我无法检查对象的值。有什

使用以下代码:

let decoded = NSJSONSerialization.JSONObjectWithData(data as! NSData, options: NSJSONReadingOptions.MutableContainers, error:  nil) as! [String:AnyObject]
我得到了
[纬度:40.3654922,韩元:1,经度:49.9384457,温尼里德:552e]


现在我想检查对象是否等于“1”,并执行一些操作。但我无法检查对象的值。有什么办法吗?

使用swift 1.2,您可以:

if let won = decoded["won"] as? Int {
    if won == 1 {
        // do something
    }
}
if let won = decoded["won"] as? Int where won == 1 {
    // do something
}
看看swift 1.2发行说明(包含在Xcode 6.3发行说明中),我们发现,
if let
现在支持多条件检查。例如:

if let a = foo(), b = bar() where a < b,
   let c = baz() {
}
如果设a=foo(),b=bar(),其中a

如果someValue>42&&someOtherThing<19,让a=getoptionalshing(),其中a>someValue{
}

非常强大

使用swift 1.2,您可以执行以下操作:

if let won = decoded["won"] as? Int where won == 1 {
    // do something
}
看看swift 1.2发行说明(包含在Xcode 6.3发行说明中),我们发现,
if let
现在支持多条件检查。例如:

if let a = foo(), b = bar() where a < b,
   let c = baz() {
}
如果设a=foo(),b=bar(),其中a

如果someValue>42&&someOtherThing<19,让a=getoptionalshing(),其中a>someValue{
}
非常强大