鉴于'结果'在NSD阵列的NSD阵列对象
中我如何删除需要临时常量 r :
for result in results {
let r :NSDictionary = result as NSDictionary
println(r.valueForKey("heading"))
}
答案 0 :(得分:1)
对救援进行类型推断。显式输入结果'as NSDictionary'应该有效,但类型推断已经知道循环迭代器是NSDictionary。以下代码将正确输出'value1'和'value2'。
var results = [NSDictionary]()
results.append(["heading": "value1", "anotherKey": "anotherValue1"])
results.append(["heading": "value2", "anotherKey": "anotherValue1"])
for result in results {
println(result.valueForKey("heading"))
}