Re: Saving preferences tutorial
Re: Saving preferences tutorial
- Subject: Re: Saving preferences tutorial
- From: Chris Parker <email@hidden>
- Date: Mon, 30 Jun 2003 18:41:58 -0700
On Monday, June 30, 2003, at 6:25 PM, Jeff Harrell wrote:
I don't know of a tutorial, but it's really as simple as:
[[NSUserDefaults standardUserDefaults] setObject:@"someValue"
forKey:@"someKey"];
You can do it with any object, such as a string as shown here, an
NSColor, an NSArray, an NSDict, whatever. You can also use setBool:,
setFloat:, or setInteger: instead if you want to store one of those
values.
Careful... :)
-setObject:forKey: on NSUserDefaults only works for "plist" types, as
Dave Thorup indicated in his message earlier in this thread. To quote:
The object types that you can save with NSUserDefaults are as follows:
NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary
If you're going to store anything else in preferences, you'll have to
massage them into one of these types.
For NSColors, the best way to do this (keeping fidelity) is to use
NSArchiver to change the NSColor into an NSData and then store that.
When you read the value from NSUserDefaults, unarchive it back into an
NSColor. Sample code for this is likely available in the mailing list
archives.
.chris
--
Chris Parker
Cocoa Frameworks
Apple Computer, Inc.
_______________________________________________
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.