How to change the app preference settings through code?

Solutions Collect From Internet About “How to change the app preference settings through code?”

Nice and simple:

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

NSUserDefaults includes convenience methods for setting ints, floats, strings, and so on. You can also just use -setValue:forKey:.

When you change a value in your app using NSUserDefaults, the setting well change in the Settings app, too.