iosarraysswiftloopshashable

Looping an AnyHashable Dictionary


I am trying to loop the information that I got from a Http response, but I am having trouble accessing the data. this is currently the information I am trying to Loop: enter image description here

I was trying to use a For to access the different elements of the response but cant figure out how to access the elements inside the dictionary, this is the code I am using:

var dictionaryMessage: NSMutableDictionary?
            do {
                if let data = result?.data(using: .utf8) {
                    dictionaryMessage = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? NSMutableDictionary
                    if(dictionaryMessage?["precios"] != nil){
                        var element = dictionaryMessage?["precios"]
                        for (index, element) in element![0]{
                            print("index" + index + "element:" + element)
                        }
                    }
                }
            } catch {
                //error handling
            }
            

I was hoping to find the correct method to access this data, because at the moment I am getting this error: enter image description here


Solution

  • You can try

    var element = dictionaryMessage!["precios"] as! [[String:Any]]