Reputation: 3
I have the following core data model with two entities:
entity "item" which holds name, date, description and a to many relationship "image". image is optional.
entity "image" holds url, name and relationship to one item.
I load the executed Fetchrequest into this NSArray "entityArray"
This is what I do to display my data in a UITableView for example to display title in main cell:
NSManagedObject *object = (NSManagedObject *)[entityArray objectAtIndex:indexPath.row];
cell.textLabel.text=[object valueForKey:@"title"];
Now I have no clue how to access my relationship image ([object valueForKey:@"image"]), because it contains more than just a string.
Upvotes: 0
Views: 1123
Reputation: 46718
First, -objectAtIndex:
returns an id
so no casting is required.
Second you can access the image the same way you accessed the title:
NSSet *images = [object valueForKey];
You can then iterate over that set and pick the image you want to work with.
Upvotes: 3