In my app I have complicated architecture, so a little bit of theory at start. When I receive remote notification I call
NotificationCenter.default.post(Notification.Name("myName"),
object: nil,
userInfo: userInfo)
in AppDelegate
.
In another file I made an UIViewController
extension with selector function like:
func myFunction(_ notification: Notification) { }
Now what I do in one of my view controllers (let's call him MyVC) I call
override viewWillAppear(_ animated: Bool) {
NotificationCenter.default.addObserver(self,
selector:#selector(myFunction),
name: Notification.Name("myName"),
object: nil)
}
MyVC
contains array with objects. When application receives a push notification I need to process this array inside myFunction
but in fact I don't know how to pass it.
What I tried was adding extra argument into selector function but unsuccessfully. Can I achieve it somehow?
Edit: And what about passing my array into the object
parameter inside .addObserver
function? Will I be able to get it in myFunction
by calling notification.object
?