Re: Saving preferences tutorial
Re: Saving preferences tutorial
- Subject: Re: Saving preferences tutorial
- From: Dave Thorup <email@hidden>
- Date: Mon, 30 Jun 2003 19:04:20 -0600
On 6/30/03 6:34 PM, "Chad Armstrong" <email@hidden> wrote:
>
Is there a good tutorial available on saving preferences? Of the one
>
or two I've found, they seem a little more complicated than it seems
>
like it should be. I would like the ability to just save a few values
>
such as a radio button or color. Thanks.
I don't know what you've looked at, but NSUserDefaults is the standard API
for saving preferences in Cocoa. It's really quite easy, here is an
example:
<Warning - typed in Mail, use at your own risk>
-----------------------
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
// saving the string "I Saved it" to preferences with key = "didSave"
[defaults setObject:@"I Saved it" forKey:@"didSave"];
// now write it out to disk by synchronizing
[defaults synchronize];
// now read the key from the preferences
NSString* str = [defaults objectForKey:@"didSave"];
-----------------------
The object types that you can save with NSUserDefaults are as follows:
NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary
Your application's preferences will be saved in ~/Library/Preferences/ in a
file with your application's bundle identifier. For example
"com.apple.Safari" NSUserDefaults is a really nice API and is quite easy to
use.
<shameless plug>
By the way, you can use my tool, Defaults Manager <
http://www.kuwan.net> to
view, edit, and backup preferences stored with NSUserDefaults.
</shameless plug>
____________________________________
Dave Thorup
Software Engineer
email@hidden
www.kuwan.net
Defaults Manager - The premier editor for Mac OS X's User Defaults /
Preferences database.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.