error Ambiguous reference to member 'subscript'

I'm getting an error that says: Ambiguous reference to member 'subscript'

What does this mean and what should I check to fix this?

Accepted Reply

dictionary
is of type
[String:UIImage]
but you’re indexing it with type
URLThumbnailDictionaryItem
, which is not a string. To get a string from the latter, you need to access the
rawValue
property.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

The error comes in this code from Apple's ShapeEdit sample project, where dictionary[] is accessed.


fileprivate func loadThumbnailFromDiskForURL(_ URL: Foundation.URL) -> UIImage? {

do {

/

Load the thumbnail from disk. Use getPromisedItemResourceValue because

the document might not have been downloaded yet.

*/

var thumbnailDictionary: AnyObject?

try (URL as NSURL).getPromisedItemResourceValue(&thumbnailDictionary, forKey: URLResourceKey.thumbnailDictionaryKey)

/

We don't want to hang onto this in the URL cache because the URL

is long running and we maintain a separate cache for the thumbnails.

*/

(URL as NSURL).removeCachedResourceValue(forKey: URLResourceKey.thumbnailDictionaryKey)

guard let dictionary = thumbnailDictionary as? [String: UIImage],

let image = dictionary[URLThumbnailDictionaryItem.NSThumbnail1024x1024SizeKey] else {

throw ShapeEditError.thumbnailLoadFailed

}

return image

}

dictionary
is of type
[String:UIImage]
but you’re indexing it with type
URLThumbnailDictionaryItem
, which is not a string. To get a string from the latter, you need to access the
rawValue
property.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"