Singelton design is a good approach. For for a login use case, you really need not have to have a singelton. You can still go with Observer design pattern. Singleton is really nice while using CoreData or persistent storage or many operations that needs a common unique controller across the app.
Here is how you can implement the Observer pattern.
- Create A
LoginViewController.
- In App Delegate, add an observer method that keeps looking for Session Validity & takes care of presenting LoginController.
- On
viewDidLoad of each TabBarController items, perform the Session validity Check.
- If session is not valid, trigger trigger the notification so that the observer can listen to it & respond accordingly.
This is far simpler approach. In combination with Singleton, the Observer pattern provides you a robust scalable approach.
Updated Code
----------------------------------------------------------
Please find LoginObserver Code here
----------------------------------------------------------
Hope that helps.