Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does fast enumeration evaluate the collection expression on every iteration?

If I have the following piece of code:

        for (UIView *view in [myArray copy])

Does that mean that I'm sending the copy message to myArray on every iteration, or Objective-C is smart enough to do copy only once, and use it for the whole loop?

like image 619
Devfly Avatar asked May 08 '13 20:05

Devfly


1 Answers

It isn't a matter of "smart", but yes, the expression [myArray copy] is evaluated once up front.

like image 147
matt Avatar answered Nov 19 '22 23:11

matt