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:@"%[email protected]", theKey]]; [encoder encodeFloat:components[1] forKey:[NSString stringWithFormat:@"%[email protected]", theKey]]; [encoder encodeFloat:components[2] forKey:[NSString stringWithFormat:@"%[email protected]", theKey]]; [encoder encodeFloat:components[3] forKey:[NSString stringWithFormat:@"%[email protected]", 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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/jon.nall%40gmail.com

This email sent to [email protected]

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to