user979331 user979331 - 2 months ago 12
Swift Question

Swift 3 Type 'Any' has no subscript members

I just converted my project to Swift 3 I have this line of code here:

let type = self.data[indexPath.row]["Type"] as? String


but now I get this error:

Type 'Any' has no subscript members


Why am I getting this error and do I fix it?

Answer
let type = (self.data[indexPath.row] as? [String : String])?["Type"]

You need to cast self.data[indexPath.row] to a dictionary.