When I was looking how to call a function from another view when this view is dismissing I found out that the NotificationCenter was a good solution so I tried to use it like this:
In my Main view (ViewController) where I want to call the function I put this:
NotificationCenter.default.addObserver(
self,
selector: #selector(ViewController.loyalty),
name: NSNotification.Name("loyalty"),
object: nil)
In my Second view before I call self.dismiss(animated: true, completion: nil)
I call this to trigger the observe:
NotificationCenter.default.post(name: NSNotification.Name("loyalty"), object: nil)
Finally after the swift 4 update my function loyalty
has @objc
before the func
and it is like this:
@objc func loyalty(){
}
PS I tried also with NSNotification.Name(rawValue: "loyalty")
Maybe I have forgot to do something?
Thanks in advance!
EDIT:
The function was executing after all I forgot to remove some arrays and that's why I thought it was not working.