문제

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.

도움이 되었습니까?

해결책

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top