Question

In my NSFetchedResultsController I want to have an NSPredicate which only fetches objects with certain relationships.

For example:

I have three subclassed NSManagedObjects: Flight, Aircraft, Battery.

Every Flight has one Aircraft. Every Flight can have several Battery objects.

So when I am fetching the Flight objects, this is something I have tried with the predicate: [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"aircraft = %@", aircraftObj]];

So I only want to fetch the Flight objects which are related to that specific Aircraft object. This doesn't work, but how can I do this?

Secondly, building on that, the Flight has batteries which is an NSSet of Battery objects. So if I want to do the same as the Aircraft, but filter the Battery objects, how would I do this?

Thanks, let me know if I need to explain further.

Was it helpful?

Solution

You have a problem of "double formatting" your predicate.

You could simply write:

[NSPredicate predicateWithFormat:@"aircraft = %@", aircraftObj]

the same would go for your Battery objects (but with the proper Flight)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top