is it possible to pass array as obj via nsnotification

Viewed 6688

I could do this by using protocol and delegate but I would like to try with NSNotification

My task is sending an NSMutableArray via notification from one to another view. Is it possible to do

[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:myArray];

Then, in the receiver, how can I get the passed myArray. I was reading and confused about the userInfo and object of notification object.

Please advice me on this issue.

4 Answers

Swift 4, Swift 5

NotificationCenter.default.post(name: Notification.Name("favoriteIsDeleted"), object: [message, self.viewModel.deleteSuccessIcon])

@objc func favoriteIsDeleted(notification: Notification) {
    guard let object = notification.object as? [String?], let message = object[0], let deleteSuccessIcon = object[1] else { return }
    // Code here ...
}
Related