• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: saving NSColors to NSUserDefaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 unarchiveObjectWithData: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?


References: 
 >saving NSColors to NSUserDefaults (From: email@hidden)

  • Prev by Date: Re: Creating shared classes
  • Next by Date: Re: API for adding dictionary to MacOS ?
  • Previous by thread: saving NSColors to NSUserDefaults
  • Next by thread: Viewing all notifications on a system
  • Index(es):
    • Date
    • Thread