Re: NSThread/NSMutableArray oddity
Re: NSThread/NSMutableArray oddity
- Subject: Re: NSThread/NSMutableArray oddity
- From: Matt Majka <email@hidden>
- Date: Fri, 12 Apr 2002 07:31:19 -0600
On Thursday, April 11, 2002, at 11:41 pm, j o a r wrote:
On Friday, April 12, 2002, at 06:31 , Matt Majka wrote:
New problem. Having trouble setting an array of NSColors
as a user default. Any ideas there?
You should not store things in NSUserDefaults that aren't a valid
property list object - ie. either: NSData, NSString, NSNumber, NSDate,
NSArray or NSDictionary.
Other objects, objects in the object hierarchies rooted in an array or
dictionary, or plain data types, needs to be converted into one of these
first in order to be accepted by the user defaults system.
In your case that means that you need to convert your array of NSColor
into an array of NSData doing something like this (original code from Ali
Ozer in the thread "saving NSColors to NSUserDefaults" on this mailing
list):
NSData *data = [NSArchiver archivedDataWithRootObject:color];
[[NSUserDefaults standardUserDefaults] setObject:data
forKey:@"MyColor"];
To read it back you would do:
NSData *data = [[NSUserDefaults standardUserDefaults]
objectForKey:@"MyColor"];
NSColor *color = [NSUnarchiver unarchiveObjectWithData:data];
This is not very well documented for NSUserDefaults - just hinted at
indirectly, like in the description for the method
"persistentDomainForName:". Someone should report this through RadarWeb
to have the documentation updated and improved.
That did it. Thanks.
_______________________________________________
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.