I miss something in the logic.
The notification is sent by FavoritesVC. But where is currentFav initialised ?
And why don't you simply append in HockeyDetailVC ?
In your IBAction
@IBAction func addToFav(_ sender: Any) {
let alert = UIAlertController(title: "Favourite Added 💙", message: "\(name.text ?? "") is added to favourites", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
self.present(alert, animated: true, completion: nil)
print("Favourite button Pressed")
let passDataVC = FavouritesVC() /* I think passDataVC is supposed to be different because I use storyboard but I don't know what else it's supposed to be. */
self.present(passDataVC, animated: true, completion:nil)
}
Line 5 and next will be executed before you tap OK.
Is it what you want ?
In addition, you will probably have an error like:
2021-03-31 15:20:44.949122+0200 simpleTest[54293:11989110] [Presentation] Attempt to present xxxx.FavouritesVC: 0x7fbfd14534c0 on xxxx.HockeyDetailVC: 0x7fbfd3014000 (from xxxx.HockeyDetailVC: 0x7fbfd3014000) which is already presenting UIAlertController: 0x7fbfd1877a00.
I changed as follows to make it work (call the next VC in the completion of button).
FavViewID is the ID of FavouritesVC
@IBAction func addToFav(_ sender: UIButton) {
let alert = UIAlertController(title: "Favourite Added 💙", message: "\(name.text ?? "") is added to favourites", preferredStyle: .alert)
alert.addAction(UIAlertAction(
title: "OK",
style: UIAlertAction.Style.default,
handler: { _ in
DispatchQueue.main.async { // pour update UI
if let passDataVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FavViewID") as? FavouritesVC {
self.present(passDataVC, animated: true, completion: nil)
}
}
}))
self.present(alert, animated: true, completion: { print("Favourite button Pressed") } )
}