Swift Error: Ambiguous reference to member 'subscript' Swift Error: Ambiguous reference to member 'subscript' swift swift

Swift Error: Ambiguous reference to member 'subscript'


Just specify explicitly what is the type of pictures:

So instead of:

let pictures = selectedRestaurant["Pictures"] as! NSArray

Write:

let pictures: NSArray = selectedRestaurant["Pictures"] as! NSArray


For me the answer was to specifically state the type of array I was casting to:

if let foo = dictionary["bar"] as? [String]


It means that "Pictures" is not a valid subscript. It looks like you are creating a constant named pictures and you are trying to assign it a value of selectedRestaraunt["Pictures"] and then trying to cast it as an NSArray. If selectedrestaraunt is already an array, then what goes in the [] brackets after selectedRestaraunt should be an integer value which will refer to an index in the selectedRestaraunt array. Obviosuly "Pictures" is not an integer, it is a string.

If you are trying to access an array within an array. Meaning that Pictures is an array stored within the selectedRestarauntarray then you can access it by using selectedRestaraunt[index of Pictures array] where [index of pictures array] is an integer which is equal to the index number in which the Picutres array resides within the selectedRestaraunt array