Is there a way to formulate a Core Data predicate for a given object, representing the head of a singly linked list, and all of the other objects in that list?
E.g., I have objects, each of which has a relationship to another object (say nextObject) and I want a predicate for a specified object and all other objects reachable by traversing nextObject (until it is nil).
CLARIFICATION:
I’m using these for a UITableView‘s NSFetchedResultsController, so these need to be part of the fetch, not something I iterate through in code.
You wouldn’t use a predicate for a linked list. Instead, you would just start with the first object of interest and walk the relationships by calling
nextObjectuntil you hit one that did not have anextObjectvalue.You can find the first and last objects with a predicate in a fetch just by looking for
previousObject==nilandnextObject==nil.Predicates do not understand arbitrarily long relationship chains. They understand a chain like
enity1.entity2.entity3but notnextObject.nextObject.nextObject...because they have no way of knowing when to stop.