Sebastien Peek Sebastien Peek - 1 year ago 103
Objective-C Question

iOS: Use a boolean in NSUserDefaults

When the

of my application is loaded, I want to be able to check whether or not the users login credentials have been saved to

Basically, when the user loads the application and he/she doesn't have her login credentials saved, a
will be pushed and the user will be able to save their credentials appropriately. This saves those
strings to a respective
object. However, is it possible, that when this saving is done, I can create an
object which is a boolean and change the value to a yes?

Meaning that the boolean is already set to no, and when the user saves their login credentials, it also changes the boolean to a yes?

Answer Source

You can set your boolean by using:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"logged_in"];

and read it by using this code:

if(![[NSUserDefaults standardUserDefaults] boolForKey:@"logged_in"]) {
    [self displayLogin];
} else {
    [self displayMainScreen];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download