HusseinB
HusseinB

Reputation: 1341

setting a predicate for fetch request

i'm using core data and in the function:

- (NSFetchedResultsController*)fetchedResultsController()

i want to use a predicate that can let the NSFetchRequest return the managed objects that has a given relationship value. i tried this:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"belongToS like[cd] %@", (S*)self.s];
    [fetchRequest setPredicate:predicate];

Note: 
- belongToS: relationship of type (S *)
- self.s is a managed object casted to type (S *) since it is of NSManagedObject and actually it's truly an object of type (S *).

when i run the code it doesn't return anything! how can i edit it to make it work? and is there any optimal solution for fetching objects that has the same relationship value?

Upvotes: 0

Views: 451

Answers (1)

Martin R
Martin R

Reputation: 540045

LIKE in a predicate is only for comparing strings. To fetch all objects that are related to self.s, the following should work:

[NSPredicate predicateWithFormat:@"belongToS = %@", self.s];

Upvotes: 1

Related Questions