Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store ON/OFF switch in NSUserDefaults?

I have an app where I use NSUserDefaults to determine if it is the first time someone opens the app. If it is the first time, the app displays a tutorial page.

Now, I would like to change this so that if the user moves an ON/OFF switch to "ON", they will not see the tutorial when they start up the app. How do I store the user's selection of an ON/OFF switch in NSUserDefaults?

like image 280
user1486548 Avatar asked Mar 02 '26 13:03

user1486548


1 Answers

I did something like this with the following code:

Store it:

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:YES forKey:@"the_key"];
[[NSUserDefaults standardUserDefaults] synchronize]; //Thanks Henri Normak

Retrieve it:

[[NSUserDefaults standardUserDefaults] objectForKey:@"the_key"]
like image 163
ratbum Avatar answered Mar 04 '26 02:03

ratbum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!