user1800529
user1800529

Reputation: 91

NSPredicate to fetch the specific data in the NSSet CoreData?

I have table A and B. A and B have one to many relationship.I am fetching data from the A but while fetching data i get all the data of B in NSSet.But I Want to have some specific data of B in NSSet while i am fetching data from A.

Upvotes: 2

Views: 425

Answers (1)

Rahul Wakade
Rahul Wakade

Reputation: 4805

You can apply predicate on NSSet. NSSet has instance method-

- (NSSet *)filteredSetUsingPredicate:(NSPredicate *)predicate

Example from apple documentation

NSSet *sourceSet =
    [NSSet setWithObjects:@"One", @"Two", @"Three", @"Four", nil];
NSPredicate *predicate =
    [NSPredicate predicateWithFormat:@"SELF beginswith 'T'"];
NSSet *filteredSet =
    [sourceSet filteredSetUsingPredicate:predicate];
// filteredSet contains (Two, Three)

Upvotes: 2

Related Questions