I’ve got an App with different ViewControllers which are managed in an Navigation Controller. In one ViewController I’m making a Request to my WebService to authenticate the user. I’m writing the respond in an BOOL (isLoggedIn). Now I need to use this BOOL and the username in different ViewControllers. I need the variable to change a Custom Navigation Button Title (Login -> Logout). Also in an other ViewController I’ve to send something to my WebService, but only an Authenticated User (isLoggedIn) is permitted to make the call.
I hope it’s well enough explained 🙂
So what possibilites do I have to make this work? I’ve read something to create a Singleton Class, is this the proper way?
Or should I make somehow a connection from my LoginViewController to the affected ViewControllers?
How can I do this? Right now I’ve just used the method prepareForSegue to reference a DetailViewController and pass the data.
You can make a singleton implementation like:
Then have sharedVar be a property of the class. From anywhere in the app, you can use:
to access it.