• 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: NSColor <-> NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSColor <-> NSString


  • Subject: Re: NSColor <-> NSString
  • From: Vince DeMarco <email@hidden>
  • Date: Tue, 25 Dec 2001 10:24:13 -0700

On Tuesday, December 25, 2001, at 07:28 am, Simson Garfinkel wrote:

thanks for the pointer. A bit more complicated than what I want, to be sure.
I was hoping that there would be some simple thing in the AppKit for
transforming a Color into a String, the way there is stuff for coding other
basic values into strings. I don't want a list of colors; I just want one
color. I guess I'll need to write it.


You can't really do this directly in the AppKit, what you can do is archive a Color, into an NSData object, then set the data in the preferences.

Here is the code to archive the color

data = [NSMutableData data];
archiver = [[NSArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeRootObject:color];
[archiver release];


do something with data

then to unarchive it

get the data

color = [[NSUnarchiver unarchiveObjectWithData:data] retain];

vince

I think that one of the fundamental differences between _Cocoa Programming
for Mac OS X_ and the book that I am doing with Michael Mahoney is that our
code examples all try to be as compact as possible, to show off the essence
of the AppKit. There are a few exceptions to this, but in general, we've
tried to design all of the applications in this manner.

NSColorList has
-(NSColor *) colorWithKey:(NSString *) key

On page 296 of the new _Cocoa Programming for Mac OS X_ book, there is
an example class ColorFormatter which as an NSFormatter converts from
Strings to NSColors and vice-versa.
It has some code for converting from an arbitrary color to the nearest
named color string in an NSColorList, and searching through color lists
for substrings.
_______________________________________________
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.


References: 
 >Re: NSColor <-> NSString (From: "Simson Garfinkel" <email@hidden>)

  • Prev by Date: Re: NSColor <-> NSString
  • Next by Date: PBX No Slide Hack v2
  • Previous by thread: Re: NSColor <-> NSString
  • Next by thread: Re: Getting internet connection.
  • Index(es):
    • Date
    • Thread