See Fast enumeration iteration variables in the Clang "Objective-C Automatic Reference Counting" documentation:
If a variable is declared in the condition of an Objective-C fast enumeration loop, and the variable has no explicit ownership qualifier, then it is qualified with
const __strong
and objects encountered during the enumeration are not actually retained.Rationale
This is an optimization made possible because fast enumeration loops promise to keep the objects retained during enumeration, and the collection itself cannot be synchronously modified. It can be overridden by explicitly qualifying the variable with__strong
, which will make the variable mutable again and cause the loop to retain the objects it encounters.
So by default, the loop variable is immutable, and the retain count of the current object is not increased for performance reasons.
If you explicitly declare the loop variable as __strong
, it is a mutable strong reference, and the retain count of the current object is increased, and setting the loop variable to nil
decreases the retain count again. But doing so does not deallocate the object or remove it from the array, because the array holds another strong reference to the object.