ios - Objective C: loop efficiently through particular range of elements within NSArray -


i loop though part of nsarray, example position 700 950 in array 1000 objects.

i don't think using [array objectatindex:index] approach here, since it's slower quick iteration using (object *obj in array)

what best approach in case? considering using

for (object *obj in [array subarraywithrange]]) not sure overhead be, since subarray created this.

are there other options?

you can use enumerateobjectsatindexes: enumerate array @ indexes in nsindexset, can generated range.

nsindexset *indexset = [nsindexset indexsetwithindexesinrange:nsmakerange(700, 950)];  [array enumerateobjectsatindexes:indexset options:kniloptions usingblock:^(id obj, nsuinteger idx, bool *stop) {  }]; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -