AppyMike
AppyMike

Reputation: 2064

Core Data accessing relationships with Duplicates

I'm using the following to get an array of all of the gifts bought for a single person. itemName is the name of the gift and giftDetails is a one-to-many relationship with the person. i.e one person has many gifts

NSSet *set=[[object valueForKey:@"giftDetails"] valueForKey:@"itemName"];
NSArray *array=[set allObjects];

This code is fine unless there are duplicate itemNames. After researching I understand that NSSet automatically removes duplicates.

So what I am asking is if there is another way to get the giftDetails without using NSSet as I want to access the duplicates too.

Thanks!

Upvotes: 0

Views: 82

Answers (1)

Martin R
Martin R

Reputation: 539765

NSArray *allGiftDetails = [[object valueForKey:@"giftDetails"] allObjects];
NSArray *allGiftNames = [allGiftDetails valueForKey:@"itemName"];

should to the trick.

Upvotes: 1

Related Questions