CoreData and NSAttributedString

  • Hi,

    I need to store NSAttributedStrings of small to medium size (max
    maybe 20 lines of text) in a CoreData store.

    My idea is to archive the attributed string and store the result as
    single binary data attribute. Is this reasonable? The typical
    approach? Other ways to handle it?

    Thanks a lot
    Kai
  • > I need to store NSAttributedStrings of small to medium size (max
    > maybe 20 lines of text) in a CoreData store.
    >
    > My idea is to archive the attributed string and store the result as
    > single binary data attribute. Is this reasonable? The typical
    > approach? Other ways to handle it?

      In fact that's really the *only* way to store nonstandard attribute
    types. This page in the Core Data docs covers the important parts:

    http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles
    /cdNSAttributes.html


    --
    I.S.
  • On 12/4/07 7:25 PM, Kai Brüning said:

    > I need to store NSAttributedStrings of small to medium size (max
    > maybe 20 lines of text) in a CoreData store.
    >
    > My idea is to archive the attributed string and store the result as
    > single binary data attribute. Is this reasonable? The typical
    > approach? Other ways to handle it?

    That's reasonable, and typical.  If you can require 10.5, just use a
    'transformable' property, since NSAttributedString conforms to NSCoding,
    everything will magically work.  See the Core Data docs for more.

    --
    ____________________________________________________________
    Sean McBride, B. Eng                <sean...>
    Rogue Research                        www.rogue-research.com
    Mac Software Developer              Montréal, Québec, Canada
  • > If you can require 10.5, just use a
    > 'transformable' property, since NSAttributedString conforms to NSCoding,
    > everything will magically work.  See the Core Data docs for more.

      Ack! I hadn't had a chance to re-read the Core Data docs for Leopard
    goodness ... I had completely overlooked this new option. Nice.

    --
    I.S.
  • On Dec 4, 2007, at 10:25 AM, Kai Brüning wrote:

    > My idea is to archive the attributed string and store the result as
    > single binary data attribute. Is this reasonable? The typical
    > approach? Other ways to handle it?

    Archiving it is reasonable.  Depending on the sort of text you are
    storing and the use you are making of it, you might also wish to
    consider storing it in one of the standard persistent data formats
    that the text system supports, such as RTF, HTML, and so forth.

    Douglas Davidson
  • Thanks for your answers, now I'm sure I'm heading in the right direction.

    Transformable attributes are cool, I'll sure use them for future 10.5-only projects.

    Kai

    > Hi,
    >
    > I need to store NSAttributedStrings of small to medium size (max maybe 20 lines of text) in a CoreData store.
    >
    > My idea is to archive the attributed string and store the result as single binary data attribute. Is this reasonable? The typical approach? Other ways to handle it?
    >
    > Thanks a lot
    > Kai
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today