Swift 4 or later
Declare a notification name to be used
extension Notification.Name {
static let refresh = Notification.Name("refresh")
}
Add an observer for that name in your view controller viewDidLoad method and a selector to get the notification object
NotificationCenter.default.addObserver(self, selector: #selector(refreshList), name: .refresh, object: nil)
@objc func refreshList(_ notification: Notification) {
if let object = notification.object as? [String: Any] {
if let id = object["id"] as? Int {
print(id)
}
if let email = object["email"] as? String {
print(email)
}
}
}
Post your notification with your object:
let object: [String: Any] = ["id": 1, "email": "abc@def.com"]
NotificationCenter.default.post(name: .refresh, object: object)