• 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: Evadne Wu <email@hidden>
  • Date: Mon, 27 Feb 2012 16:02:18 +0800

A very naïve suggestion is that if you are targeting OS X you might be
able to use HTML or RTF.  Save that and convert the stored into to an
attributed string at run time.

One idea of font descriptors is that a particular font may not exist
on a particular computer, but similar ones might be available.  When
the end result is created as an attributed string that info is already
lost.

On Feb 27, 2012, at 14:33, Heath Borders <email@hidden> wrote:

> 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.
>
>
> How do you create a category for a Foundation type that isn't an
> Objective-C class? And why would that get you rejected?
>
> Sent from my iPad
>
> On Feb 27, 2012, at 12:21 AM, Jens Alfke <email@hidden> wrote:
>
>
> 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
> _______________________________________________
>
> 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


References: 
 >issues using encodeWithCoder: with NSAttributedString for iOS (From: Michael Swan <email@hidden>)
 >Re: issues using encodeWithCoder: with NSAttributedString for iOS (From: Jens Alfke <email@hidden>)
 >Re: issues using encodeWithCoder: with NSAttributedString for iOS (From: Heath Borders <email@hidden>)

  • Prev by Date: Application Suite Preferences
  • Next by Date: Bug in 10.6 NSPasteboard API? (was: 10.6 NSPasteboard API mixes up types?)
  • Previous by thread: Re: issues using encodeWithCoder: with NSAttributedString for iOS
  • Next by thread: Application Suite Preferences
  • Index(es):
    • Date
    • Thread