• 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: How do you store an NSArray as an attribute in a Core Data entity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you store an NSArray as an attribute in a Core Data entity


  • Subject: Re: How do you store an NSArray as an attribute in a Core Data entity
  • From: Mic Pringle <email@hidden>
  • Date: Thu, 19 Mar 2009 12:10:47 +0000

Have a look at the following ...

http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html#//apple_ref/doc/uid/TP40001919

-Mic

2009/3/19 Chris Hanson <email@hidden>:
> On Mar 19, 2009, at 1:26 AM, email@hidden wrote:
>
>> I want to store a list of Strings as an attribute of an entity in Core
>> Data but there doesn't appear to be a way to use NSArray (or NSSet or
>> NSDictionary either) as an attribute.?Please can someone explain how you use
>> an NSArray or NSDictionary as an attribute of a Core Data entity?
>
> In general, if you want to have multiple things as an attribute of a Core
> Data entity, what you really want is a to-many relationship with another
> entity.
>
> Let's take tags as an example.  Say I'm creating a weblog editor and I want
> the ability to tag my posts.  I could model this as a string attribute with
> some specific format (space- or comma-separated), or as a transformed
> attribute.  However, that doesn't get me the ability to do things like say
> "show all the posts with this tag" or even "auto-complete known tags."  It
> also leads to persistent store bloat because I'm breaking a cardinal rule of
> relational data, "store each piece of data once," because each tagged post
> winds up with a copy of the tag's text.
>
> Instead of having an attribute, I would model a to-many relationship from my
> Post entity to my new Tag entity, with a to-many inverse relationship from
> my Tag entity to my BlogPost entity.  This way:
>
> Each Tag instance only exists once in the persistent store.
> I can traverse the object graph between Posts and Tags, and between Tags and
> Posts, with ease.
> I can perform interesting queries across both Posts and Tags to improve my
> user experience (e.g. support auto-completion or generate tag clouds).
> Not having Tags stored directly on Posts means if I'm just dealing with a
> Post, Core Data won't bother fetching the Tags too.
>
> Entities and relationships are good, hope this helps you leverage them!
>
>  -- Chris
>
> _______________________________________________
>
> 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: 
 >How do you store an NSArray as an attribute in a Core Data entity (From: email@hidden)
 >Re: How do you store an NSArray as an attribute in a Core Data entity (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: How do you store an NSArray as an attribute in a Core Data entity
  • Next by Date: Re: [Q] Contextual Menu Items Size
  • Previous by thread: Re: How do you store an NSArray as an attribute in a Core Data entity
  • Next by thread: NSSegmentedControl send action only from the selected segment
  • Index(es):
    • Date
    • Thread