Re: NSColor <-> NSString
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] initForWritingWithMutable
Data:data];
[archiver encodeRootObject:color];
[archiver release];
do something with data
then to unarchive it
get the data
color = [[NSUnarchiver unarchiveObjectWith
Data: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.