Context
I have a Core Data entity called “LPFile” that represents a file on disk. It has an optional relationship to itself that allows files to “import” each other, like so:
imports<<—->>importedBy
Question
Now, suppose I have this situation with Files 1, 2, 3, and 4:
File 1 is importedBY 2 and 3. Files 2 & 3 are importedBY 4. What I want to know is: if I start at file 1, what’s the most efficient approach for finding the “base” or “end” file of this relationship (in this case, that’s file 4)? I can write a simple recursive function that looks at each entity in the importedBy relationship, and follows the chain until it finds an entity with zero entities in the importedBy relationship, but I wanted to see if Core Data has a pre-baked method to do this.
Thanks!
Core Data has no pre-baked method to find a root. So your way of looping through it is fine.