user470763
user470763

Reputation:

Accessing dictionary key in Swift

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

Answers (1)

Rob
Rob

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

Related Questions