How To Create An iPhone Preferences File Display Rich Text Using a UIWebView
Mar 25

After yesterday’s elaborate tutorial on how to create a Preferences UI, accessing the preferences from your code is a snap.

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.

[userDefaults setFloat:delayBeforeDialing forKey:@"delayBeforeDialing"];

Read back the values as above.

written by Nick \\ tags:

One Response to “How To Access Preferences From Your iPhone App”

  1. Gabe Jacobs Says:

    It says the delayBeforeDialing is undeclared for the second line of code you provided.

Leave a Reply