Daniel Zapata Daniel Zapata - 1 year ago 45
Swift Question

Iterate over AnyObject. Error: Type 'AnyObject' does not conform to protocol 'SequenceType'

I'm using Alamofire to get a data from a JSON file. Example of the output:

I have a problem when I try to access the information from the JSON output.

Alamofire.request(.GET, url).responseJSON { (response) -> Void in
if let JSON = response.result.value {
for json in JSON{

The problem I have is that my JSON output is an AnyObject and I cannt iterate over an AnyObject. If I do the following:


Then I can see the output correctly. How can I iterate over an AnyObject?

Answer Source

You may need to explicitly state the type of JSON as an array of dictionaries:

if let JSON = response.result.value as [[String : AnyObject]] {
    // ...