UIAlertView replacement iOS 9

Hi there!


I have a class that is not derived from UIViewController. This class does some CoreData stuff. If something goes wrong, I have to present the user with an error message. That's what I'm doing so far with UIAlertView's show method. This method is deprecated in iOS 9. How can I present a modal UIAlertController without knowing the ViewController currently displayed?


Best regards!

Accepted Answer

You shouldn't do any UI related stuff from your "model class". Instead return an error from model class back to the view controller using the model class. Or if you really have to, post a notification through NSNotificationCenter when error occurs. Then for example the root view controller of your app (e.g. navigation controller, tab bar controller) can listen the notification and show the alert controller when needed.

"Not to see the wood for the trees."


A NSNotification object containing the current view controller. Nice!

It works like a charm. :-)


Thank you!

UIAlertView replacement iOS 9
 
 
Q