Re: NSThread/NSMutableArray oddity
Re: NSThread/NSMutableArray oddity
- Subject: Re: NSThread/NSMutableArray oddity
- From: j o a r <email@hidden>
- Date: Fri, 12 Apr 2002 07:41:47 +0200
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 unarchiveObjectWith
Data: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.
j o a r
_______________________________________________
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.