Fast Enumeration

Before Objective-C 2.0, we iterated through arrays the way you did in your main function:

f​o​r​ ​(​i​n​t​ ​i​ ​=​ ​0​;​ ​i​ ​<​ ​[​i​t​e​m​s​ ​c​o​u​n​t​]​;​ ​i​+​+​)​ ​{​
 ​ ​ ​ ​B​N​R​I​t​e​m​ ​*​i​t​e​m​ ​=​ ​[​i​t​e​m​s​ ​o​b​j​e​c​t​A​t​I​n​d​e​x​:​i​]​;​
 ​ ​ ​ ​N​S​L​o​g​(​@​"​%​@​"​,​ ​i​t​e​m​)​;​
}​

Objective-C 2.0 introduced fast enumeration. With fast enumeration, you can write that code segment much more succinctly. Make the following change in main.m:

f​o​r​ ​(​i​n​t​ ​i​ ​=​ ​0​;​ ​i​ ​<​ ​[​i​t​e​m​s​ ​c​o​u​n​t​]​;​ ​i​+​+​)​ ​{​
 ​ ​ ​ ​B​N​R​I​t​e​m​ ​*​i​t​e​m​ ​=​ ​[​i​t​e​m​s​ ​o​b​j​e​c​t​A​t​I​n​d​e​x​:​i​]​;​
 ​ ​ ​ ​N​S​L​o​g​(​@​"​%​@​"​,​ ​i​t​e​m​)​;​
}​
 f​o​r​ ​(​B​N​R​I​t​e​m​ ​*​i​t​e​m​ ​i​n​ ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.