Re: saving NSColors to NSUserDefaults
Re: saving NSColors to NSUserDefaults
- Subject: Re: saving NSColors to NSUserDefaults
- From: Ali Ozer <email@hidden>
- Date: Wed, 18 Jul 2001 10:48:47 -0700
NSColor is not a property list type, so you have to convert it to one.
The separate R, G, B representation in an NSString is not good enough
for some color representations (CMYK, patterns, system colors, etc), so
you should just archive the color as NSData:
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];
Ali
On Wednesday, July 18, 2001, at 09:27 , email@hidden wrote:
>
is there any reason this would not work?
>
>
NSColor *text = [textColorWell color];
>
[[NSUserDefaults standardUserDefaults] setObject:text
>
forKey:@"text_color"];
>
>
it seems to not like writing NSColors. if this is a problem, are they
>
any workaround short of storing the red, green, blue, and alpha values
>
separately?