Why does fast enumeration not skip the NSNumbers when I specify NSStrings?

前端 未结 8 1116
慢半拍i
慢半拍i 2021-01-14 02:27

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

8条回答
  •  借酒劲吻你
    2021-01-14 02:37

    I'm pretty sure that fast enumeration returns all objects in the array- all that you're doing in for (NSString *str in array) is typecasting str to an NSString. In the body of the loop you need to check the class of the returned object to make sure that it is an NSString.

    for(NSString *str in array)
    {
        if([str isKindOfClass:[NSString class]])
            NSLog(@"str : %@", str);
    }
    

提交回复
热议问题