Reputation: 1808
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);
}
Upvotes: 2
Views: 114
Reputation: 37
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
Upvotes: 1