In objective-c, is
for (Foo *foo in fooList) ...
more like which of the following
@interface Bar : Foo ...
for (Foo *f in fooList) {
// A:
if ([f isMemberOfClass:[Foo class]]) ... // dont include Bar's
// B:
if ([f isKindOfClass:[Foo class]]) ... // both Foos and Bars
}
It’s not like either.
The type of
fooin thefor()part is only a hint to the compiler so it can give out the relevant error messages. At run time, all the objects are just objects and as long as they all implement the methods used in the block, there will be no errors. For example:will iterate over all the objects in the array and send intValue to each one no matter what type they are including the NSString at the end. If every object implements
intValueit will work just fine (as NSString does). If there is an object in the array that does not implement intValue, an exception will most likely be thrown.