Reputation:
I'm having trouble accessing a dictionary. My code is:
if let deletedObjects: NSArray = noti.userInfo[NSDeletedObjectsKey] {
}
I get an error Cannot subscript a value of type [NSObject : AnyObject]? with an index of type String
.
Upvotes: 1
Views: 70
Reputation: 437552
The userInfo
of NSNotification
is optional, so you have to unwrap it, e.g.:
if let deletedObjects = noti.userInfo?[NSDeletedObjectsKey] as? NSArray {
// use `deletedObjects` here
}
Upvotes: 1