Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of NSManagedObject attributes

I'd like to get an array of the attributes for my NSManagedObject so I can use KVO to export them. I can create an array manually and then iterate through it, however, I'd like to get this list automatically, then iterate.

like image 707
Pete Avatar asked Nov 15 '10 18:11

Pete


People also ask

Can you store an array in Core Data?

There are two steps to storing an array of a custom struct or class in Core Data. The first step is to create a Core Data entity for your custom struct or class. The second step is to add a to-many relationship in the Core Data entity where you want to store the array.

What is NSManagedObject in Core Data?

In some respects, an NSManagedObject acts like a dictionary—it's a generic container object that provides efficient storage for the properties defined by its associated NSEntityDescription instance.

What is transformable in Core Data?

When you declare a property as Transformable Core Data converts your custom data type into binary Data when it is saved to the persistent store and converts it back to your custom data type when fetched from the store. It does this through a value transformer.


1 Answers

An NSManagedObject has an entity associated with it. Use NSEntityDescription's -attributesByName and -relationshipsByName. You'll get a dictionary back from each of those methods. Just ask the dicts for their -allKeys.

like image 94
Joshua Nozzi Avatar answered Nov 03 '22 02:11

Joshua Nozzi