How to iterate an NSSet (Objective-C) - To-Many relationship representation in Core Data - efficiently? How to iterate an NSSet (Objective-C) - To-Many relationship representation in Core Data - efficiently? ios ios

How to iterate an NSSet (Objective-C) - To-Many relationship representation in Core Data - efficiently?


The first is probably more efficient. If the latter were more efficient then Apple would simply use that route to implement the former.

That being said, if you're asking because performance seems to be an issue it's probably more that you're spending a lot of time on the Core Data stuff of faulting objects. A smart move would be to do a fetch on self in %@ with groups; set the fetch request's returnsObjectsAsFaults to NO and ensure any appropriate relationshipKeyPathsForPrefetching are specified. The net effect of that will be that all the data you're about to iterate through is fetched in a single trip to the backing store rather than each individual piece of it being fetched on demand in a large number of separate trips.