Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through NSMutableArray of custom objects in the most memory efficient way

What is the most memory efficient way to loop through an NSMutableArray of custom objects? I need to check a value in each object in the array and return how many of that type of object is in the array.

like image 304
James P. Wright Avatar asked Nov 03 '09 21:11

James P. Wright


1 Answers

for (WhateverYourClassNameIs *whateverNameYouWant in yourArrayName) {
    [whateverNameYouWant performSelector];
    more code here;
}

It's called fast enumeration and was a new feature with Objective C 2.0, which is available on the iPhone.

like image 71
refulgentis Avatar answered Oct 13 '22 21:10

refulgentis