2016-11-27 6 views
0

날씨 API에서 데이터를 가져옵니다. 설명에 액세스하는 방법을 모르겠습니다.스위프트 3 : _NSSingleObjectArray를 통해 반복하십시오.

"weather": <__NSSingleObjectArrayI 0x608000012910>(
{ 
    description = "overcast clouds"; 
    icon = 04n; 
    id = 804; 
    main = Clouds; 
} 
) 

내가 시도 :

(
    { 
    description = "overcast clouds"; 
    icon = 04n; 
    id = 804; 
    main = Clouds; 
    } 
) 

어떻게 제대로 설명을 액세스합니까 :

print(weatherDict["weather"]!.description!) 

그것은 날이했다?

답변

4
  • weather에는 사전 배열이 포함되어 있습니다.
  • description은 배열의 첫 번째 항목에있는 키입니다. 배열이 비어 있지 않은 경우

코드는 안전하고 검사 weather을 펼쳤다 :

if let weather = weatherDict["weather"] as? [[String:Any]], !weather.isEmpty { 
    print(weather[0]["description"]) // the value is an optional. 
}