On Feb 26, 2012, at 9:44 PM, Michael Swan wrote:

> the thing that doesn't make any sense is that if NSAttributedString conforms 
> to the NSCoding protocol it must be able to fully pack itself up when 
> encodeWithCoder: is called on it which means that it should already be taking 
> care of encoding the CGColor in whatever way necessary.

Archiving doesn’t work that way. Every object asks its instance variables to 
archive themselves; it’s not in charge of how they do it. NSAttributedString 
is, basically, an array of dictionaries, each of which can have arbitrary 
values in it. NSAttributedString itself doesn’t know or care what those keys or 
values are. (Note that NSAttributedString is implemented in the Foundation 
framework, which is lower level than UIKit.)

What you’re running into is that CGColor isn’t archivable — it doesn’t 
implement the protocol methods like -encodeWithCoder:. So the attributed string 
is asking the attribute dictionary to archive itself, and the dictionary asks 
its keys and values to archive themselves, and the CGColor object fails.

I don’t know of an easy workaround. Back in the day I would have suggested 
creating a category on CGColor that adds the required archiving methods, but 
doing this will get you rejected from the App Store. You may need to write a 
function that walks through a mutable attributed string and finds all color 
objects and replaces them with something serializable, and another function 
that reverses this.

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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

This email sent to arch...@mail-archive.com

Reply via email to