What's the difference between [NSNull null] and nil?

后端 未结 6 677
[愿得一人]
[愿得一人] 2020-11-30 03:07

Here\'s a context where I have seen that:

NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++) {
            


        
6条回答
  •  感动是毒
    2020-11-30 03:27

    Directly from Apple:

    The NSNull class defines a singleton object you use to represent null values in situations where nil is prohibited as a value (typically in a collection object such as an array or a dictionary).

    So in your example, that's exactly what's happening, the programmer is choosing to put a null object into the controllers array, where nil is not allowed as a value.

提交回复
热议问题