Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 3:遍历一个_NSSingleObjectArrayI_Swift - Fatal编程技术网

Swift 3:遍历一个_NSSingleObjectArrayI

Swift 3:遍历一个_NSSingleObjectArrayI,swift,Swift,我正在从天气API获取数据。我不知道如何访问描述 "weather": <__NSSingleObjectArrayI 0x608000012910>( { description = "overcast clouds"; icon = 04n; id = 804; main = Clouds; } ) 它给了我这个: ( { description = "overcast clouds"; icon = 04n; i

我正在从天气API获取数据。我不知道如何访问描述

"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.
}