Alexsander Alexsander - 10 months ago 266
Swift Question

Swift: Could not cast value of type '__NSCFArray' to 'NSDictionary'

I have JSON data from website. I made the main dictionary and I can parse every data except one sub dictionary. I get the error "Swift: Could not cast value of type '__NSCFArray' to 'NSDictionary'"

This example of my data. I cannot parse "weather" but I can parse all other dictionaries like


["name": Mountain View, "id": 5375480, "weather": (
description = "sky is clear";
icon = 01n;
id = 800;
main = Clear;
), "base": cmc stations, "wind": {
deg = "129.502";
speed = "1.41";

Snippet of code

let windDictionary = mainDictionary["wind"] as! [String : AnyObject
let speed = windDictionary["speed"] as! Double
let weather = mainDictionary["weather"] as! [String : AnyObject]


on behalf your comment...I would say windDictionary is Dictionary...

Dictionary denotes in JSON with {} and 
Array denotes with ()

So, your weather part is Array of Dictionary...You have to parse it like

 let weather = mainDictionary["weather"] as! [[String : AnyObject]]