0

I have some difficult to convert my Swift 2.2 app to Swift 3.0. I have some errors and I don't find the solution yet. Currently, my worst problem is with NSFastEnumerationIteration, I try to get records from JSON but with this error I can't. This is the screenshot of my code with the problem :

Swift 3.0 error with NSFastEnumerationInteration

Nirav D
  • 71,513
  • 12
  • 161
  • 183
ewan
  • 276
  • 2
  • 17

2 Answers2

1

In Swift 3 you need to specify the type of object,so specify the type of your data Array to [[String:Any]].

if let dataArr = data as? [[String: Any]] {
    for dd in dataArr {
        //your code for accessing dd.
    }
}
Nirav D
  • 71,513
  • 12
  • 161
  • 183
0

For in loop only knows that your variable data is an array and doesn't know anything else, so you need to provide as well the type of the content of your variable data:

let dataToParse = dataweneed.data(using: String.Encoding.utf8.rawValue)!
let jsonOptions = [JSONSerialization.ReadingOptions.mutableContainers]
let data = try JSONSerialization.jsonObject(with: dataToParse, options: jsonOptions)

// now For in loop would know that you
// could have an array of dictionaries
if let data = data as? [[String: Any]] {
  for dd in data {
    // your code
  }
}
Wilson
  • 9,006
  • 3
  • 42
  • 46