doc92606
doc92606

Reputation: 701

How to filter Through Core Data Code

I have a table view where the user can add things and it will be saved in core data. They add ingredients such as fish, pork, gluten, or whatever they're allergic to. Whenever they add this data to the table view i save the data. Then when they go to a different page I am attempting to access THAT array that has the data. I fetch the data like so:

  NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"AllergicIngredient"];
matchAgainstArray = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];

When I NSLog "matchAgainstArray", the console returns this:

"<AllergicIngredient: 0x1667c5f0> (entity: AllergicIngredient; id: 0x1667c3a0 <x-coredata://3845687F-8AAC-48FF-BB0F-8026A7771A3E/AllergicIngredient/p1> ; data: <fault>)",
"<AllergicIngredient: 0x1667ca50> (entity: AllergicIngredient; id: 0x1667c3b0 <x-coredata://3845687F-8AAC-48FF-BB0F-8026A7771A3E/AllergicIngredient/p2> ; data: <fault>)",
"<AllergicIngredient: 0x1667ca90> (entity: AllergicIngredient; id: 0x1667c3c0 <x-coredata://3845687F-8AAC-48FF-BB0F-8026A7771A3E/AllergicIngredient/p3> ; data: <fault>)",
"<AllergicIngredient: 0x1667cae0> (entity: AllergicIngredient; id: 0x1667c3d0 <x-coredata://3845687F-8AAC-48FF-BB0F-8026A7771A3E/AllergicIngredient/p4> ; data: <fault>)",
"<AllergicIngredient: 0x1667cb20> (entity: AllergicIngredient; id: 0x1667c3e0 <x-coredata://3845687F-8AAC-48FF-BB0F-8026A7771A3E/AllergicIngredient/p5> ; data: <fault>)"

)

And core data is correct for I saved 5 items, but I want the NAME of the items, not this messy clump of data.

So my question is, how can I filter through this to get the name?

Upvotes: 0

Views: 50

Answers (2)

Raymond Brion
Raymond Brion

Reputation: 332

Implement the - (NSString*) description on your ManagedObject class and return the name/title of that object plus any other information you want as a NSString. The string will be displayed when you log the object

Upvotes: 0

sapi
sapi

Reputation: 10224

Those 'messy clump of data' are the entities themselves (ie, instances of the objects modelled in Core Data).

If you want the name of the items, just access the name property for each item (or whatever you called it when you designed the model).

Upvotes: 2

Related Questions