Hello, I'm trying to read data from a plist file. The file contains a list of food items, each one containing a dictionary such as the foodName, calories, imageName, etc. However,
func loadItems() {
if let path = Bundle.main.path(forResource: "mealData", ofType: "plist") {
let tempDict = NSDictionary(contentsOfFile: path)
let tempArray = (tempDict!.value(forKey: "foodItems") as! NSArray) as Array
for dict in tempArray {
let foodName = dict["name"]! as! String //ERROR: Ambiguous use of 'subscript'
let calories = dict["calories"]! as! String //ERROR: Ambiguous use of 'subscript'
let imageName = dict["imageName"]! as! String //ERROR: Ambiguous use of 'subscript'
let imageSize = dict["imageSize"]! as! String //ERROR: Ambiguous use of 'subscript'
let imageType = dict["imageType"]! as! String //ERROR: Ambiguous use of 'subscript'
let imageLink = dict["imageLink"]! as! String //ERROR: Ambiguous use of 'subscript'
let f = FoodItem(name: foodName, calories: calories, imageName: imageName, imageSize: imageSize, imageType: imageType, imageLink: imageLink)
foodItems.append(f)
}
}
}When I'm trying to iterate through the array created, I'm receiving this error: ✖Ambiguous use of 'subscript' in all the properties (let foodName = dict["name"]! as! String, etc, etc). I'm not sure why because I casted tempArray as an Array previously in the code, so it should be considered as an array but it is not.
Any ideas? Thank you in advance