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

前端 未结 8 1127
慢半拍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:45

    for (NSString *str in array) {
    

    is a way to enumerate through all the elements in array.

    You expectative that by specifying NSString you get only the objects of that type is not correct. Rather, all the objects pointers are cast to that type (NSString*).

    Have a look at Fast Enumeration in The Objective-C Programming Language guide.

提交回复
热议问题