Home > iPhone SDK > Objective C: Read iPhone Preferences From Application

Objective C: Read iPhone Preferences From Application

You can read preferences from your iPhone Application using the NSUserDefaults class from iPhone SDK.

Here is how you can read the delay value before the phone is starting to dial a number

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
delayBeforeDialing = [userDefaults floatForKey:@"delayBeforeDialing"];

The key, “delayBeforeDialing” in this example, needs to match the Key value in Root.plist.

There are different accessor methods depending on the type of variable you want to retrieve.

* arrayForKey
* boolForKey
* dataForKey
* dictionaryForKey
* floatForKey
* integerForKey
* objectForKey
* stringArrayForKey
* stringForKey

You don’t have to use a UI for your preferences. If you just want to conveniently store values associated with your application, that you can read back later, you can use the setter methods of NSUserDefaults.

Bookmark and Share
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogosphere News
  • LinkedIn
  • Live
  • MySpace
  • Tumblr
  • TwitThis
  • Yahoo! Buzz
  • StumbleUpon
  • Technorati
  1. No comments yet.
  1. No trackbacks yet.