NSDictionary and Core Data

user1889672 picture user1889672 · May 16, 2013 · Viewed 14.5k times · Source

Please I am trying to gain some knowledge in core data. I have so far gotten the hang of creating entities and adding, retrieving and deleting values from this entity.

My question is the following. What are the possible ways of storing NSDictionary properties in an entity when using core data?

Answer

funberry picture funberry · Jun 22, 2013

you should use "Transformable Attributes":

  1. open *.xcdatamodeld file
  2. select entity
  3. add attribute (name it for example "info") and set the type as "Transformable"
  4. generate appropriate NSManagedObject subclass files (File->New->File ... NSManagedObject subclass)
  5. open *.h file and change type for property "info" from id to NSMutableDictionary*

everything else works automatically

for more information see: https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html