• 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: issues using encodeWithCoder: with NSAttributedString for iOS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: issues using encodeWithCoder: with NSAttributedString for iOS


  • Subject: Re: issues using encodeWithCoder: with NSAttributedString for iOS
  • From: Jens Alfke <email@hidden>
  • Date: Sun, 26 Feb 2012 22:14:30 -0800

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 (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


  • Follow-Ups:
    • Re: issues using encodeWithCoder: with NSAttributedString for iOS
      • From: Heath Borders <email@hidden>
References: 
 >issues using encodeWithCoder: with NSAttributedString for iOS (From: Michael Swan <email@hidden>)

  • Prev by Date: issues using encodeWithCoder: with NSAttributedString for iOS
  • Next by Date: Re: issues using encodeWithCoder: with NSAttributedString for iOS
  • Previous by thread: issues using encodeWithCoder: with NSAttributedString for iOS
  • Next by thread: Re: issues using encodeWithCoder: with NSAttributedString for iOS
  • Index(es):
    • Date
    • Thread