Reputation: 953
Let's say I have a table named "Coffee Mug" and a relationship to many types of "coffee".
I can access the Coffee Mug record and all of it's details, but when I try to get the types of coffee through the relationship I just get the pointer values.
I'm trying to create an array of coffee values like this:
self.coffeeTypeArray = [[NSMutableArray alloc] initWithArray:[coffeeMug.coffee allObjects]];
NSLog(@"Filled Array with: %i records", [self.coffeeTypeArray count]);
NSLog(@"Array contents: %@", self.coffeeTypeArray);
My log shows that the array was populated with 5 objects. But instead of the strings that I am looking for I get something like this for each record:
"<CoffeeTypes: 0x7f460b0> (entity: Coffees; id: 0x7f46100 <x-coredata:///Coffees/t113639D7-6BA1-4FDB-9739-7781EE6460134> ; data: {\n mug = \"0x7f40370 <x-coredata:///coffeeMugs/t113639D7-6BA1-4FDB-9739-7781EE6460132>\";\n coffee = Columbian;\n})"
I know the answer has to be simple, but I have run out of search terms.
Upvotes: 0
Views: 350
Reputation: 539955
What you see in the array are managed objects of the "Coffees" entity. The entity has an attribute coffee
which seems to be what you are looking for.
The following should work to print the coffee
attribute for all objects in the array:
for (CoffeeTypes *theCoffee in self.coffeeTypeArray) {
NSLog(@"%@", theCoffee.coffee);
}
Note: Perhaps you should reconsider the naming of you entities and relationships. Your "Coffees" entity represents (as I understand it) one type of coffee, so "Coffee" (without plural s) would be a better name. On the other hand, the one-to-many relationship from "CoffeeMugs" to "Coffees" is called "coffee". Here, "coffees" (with plural s) would be a better name for that relationship.
Upvotes: 1