Aldo Aldo - 2 months ago 18
iOS Question

Swift 3 : Error: Type 'Any' has no subscript member

I updated to Swift 3 and I get this error and I can't solve it.

I already read the answers:

39480150 - 38956785 - 39516199

But I couldn't solve my problem with the answers.

This is my code:

let pathperdataselezionata = Bundle.main.path(forResource: "Annuale", ofType: "plist")
let dictperdataselezionata = NSDictionary(contentsOfFile: pathperdataselezionata!) as![String:AnyObject]
let valoridataodierna = dictperdataselezionata[annoscelto]?[mesescritto]?![daymonth?] as? [Double]
let Grad = Int(valoridataodierna![0])
let Ampo:Double = valoridataodierna![1]


and I get the error on the line:

let valoridataodierna


Any help is really appreciated.

Thanks.

Answer

Try like this.

let dictperdataselezionata = NSDictionary(contentsOfFile: pathperdataselezionata!) as! [String:[String:[String:AnyObject]]]
let valoridataodierna = dictperdataselezionata[annoscelto]?[mesescritto]?![daymonth?] as? [Double]