Swift 3:遍历一个_NSSingleObjectArrayI
我正在从天气API获取数据。我不知道如何访问描述Swift 3:遍历一个_NSSingleObjectArrayI,swift,Swift,我正在从天气API获取数据。我不知道如何访问描述 "weather": <__NSSingleObjectArrayI 0x608000012910>( { description = "overcast clouds"; icon = 04n; id = 804; main = Clouds; } ) 它给了我这个: ( { description = "overcast clouds"; icon = 04n; i
"weather": <__NSSingleObjectArrayI 0x608000012910>(
{
description = "overcast clouds";
icon = 04n;
id = 804;
main = Clouds;
}
)
它给了我这个:
(
{
description = "overcast clouds";
icon = 04n;
id = 804;
main = Clouds;
}
)
如何正确访问描述?"weather": <__NSSingleObjectArrayI 0x608000012910>(
{
description = "overcast clouds";
icon = 04n;
id = 804;
main = Clouds;
}
)
weather
包含一系列字典description
是数组第一项中的一个键李>
代码安全地展开天气
并检查阵列是否为空:
if let weatherArray = weatherDict["weather"] as? [[String:Any]],
let weather = weatherArray.first {
print(weather["description"]) // the value is an optional.
}