I thought that I knew how to use fast enumeration, but there is something I don\'t understand about it. If I create three NSString
objects and three NSNum
Objective-C is dynamically typed, meaning that at runtime (when the loop actually runs), objects are all effectively one type (id
) with different classes. The language allows optional compile-time static typing, but all that does is check whether the messages you're sending are valid for the type you've marked. It doesn't actually change the behavior of your program. If you cast an object to be a different type than it actually is, all you're doing is lying to the compiler and defeating its type-checker.
The for all
loop doesn't know the difference between NSStrings and Integers -- it will simply go through the entire array, cast each as an NSString, and print them out as you asked.