ernesto
ernesto

Reputation: 1808

Check Objective-C generics type in for loop (fast enumeration)

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

Answers (1)

Sviatoslav
Sviatoslav

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

Related Questions