Is there any compiler option to warn that the type in the for-in loop is wrong?
NSArray<NSString *> *stringsArray = @[ @"Hello", @"World" ];
for (UIView *wrongType in stringsArray) {
NSLog(@"object: %@", wrongType);
}
Is there any compiler option to warn that the type in the for-in loop is wrong?
NSArray<NSString *> *stringsArray = @[ @"Hello", @"World" ];
for (UIView *wrongType in stringsArray) {
NSLog(@"object: %@", wrongType);
}
Since NSArray may contain objects of multiple classes, there are no way for compiler to detect wrong class in such for loop.
Source - iOS Programming: The Big Nerd Ranch Guide