Here is a more technical description with the gory details. Consider the code
for (object expression in collection expression) { statements }
here is what happens when you run it:
for (object in [NSDictionary
keyEnumerator]) ...
. nil
and the loop immediately terminates. break
and continue
commands, which will abort the iteration or skip to the next loop iteration as expected. nil
. This allows you to determine whether the iteration finished because a break
command was used (in which case object expression will remain set to the last object that was iterated over) or because it iterated over all the objects (in which case object expression will be set to nil
). objc_enumerationMutation
, a runtime function that normally aborts the program but which can be customized by Foundation libraries via objc_set_mutation_handler
to do something different, such as raising an exception.
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Fast-enumeration-details.html