Re: NSCoder and CGColorRef
Re: NSCoder and CGColorRef
- Subject: Re: NSCoder and CGColorRef
- From: Jon Nall <email@hidden>
- Date: Thu, 5 Nov 2009 16:02:54 -0800
I have a helper function that encodes the component float values and
then the decoder creates a CGColorRef back from those.
+(void)encodeColor:(CGColorRef)theColor
withCoder:(NSCoder*)encoder
withKey:(NSString*)theKey
{
if(theColor != nil)
{
const CGFloat* components = CGColorGetComponents(theColor);
[encoder encodeFloat:components[0] forKey:[NSString
stringWithFormat:@"%@.red", theKey]];
[encoder encodeFloat:components[1] forKey:[NSString
stringWithFormat:@"%@.green", theKey]];
[encoder encodeFloat:components[2] forKey:[NSString
stringWithFormat:@"%@.blue", theKey]];
[encoder encodeFloat:components[3] forKey:[NSString
stringWithFormat:@"%@.alpha", theKey]];
}
else
{
// Encode nil as NSNull
[encoder encodeObject:[NSNull null] forKey:theKey];
}
}
I'm still pretty new at this, though, so maybe others will know a
better way.
nall.
On Nov 5, 2009, at 3:59 PM, Alexander Cohen wrote:
How would one go about encoding a CGColorRef into a NSCoder?
thx
AC
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden