NSPredicate
is just a predicate and nothing more. It is applied to some object and
yields YES or NO. A predicate can be used for filtering an array, but since the predicate itself is applied to each single array element, it does not "know" the location
(or index) of the object being tested.
Therefore a NSPredicate
cannot create an array of NSIndexPath
s.
The NSArray
method indexOfObjectPassingTest:
can be useful to find the location
of an object in an array, but even that method has to loop over all array elements
to find the object. So it might help to make the code shorter or better readable, but
it does not change the performance.
If groupByArrayOfObjects
is really large, then you can create a mapping (an NSDictionary
) from each key to the corresponding index path first. This requires only one enumeration of the (nested) array. Then you can use this mapping to get
the index path for each element in the other array aBounchOfObjectsInAFlatList
.