[NSNull null]和nil有什么区别? [英] What's the difference between [NSNull null] and nil?
本文介绍了[NSNull null]和nil有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是一个我看到的上下文:
Here's a context where I have seen that:
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++) {
[controllers addObject:[NSNull null]];
}
为什么不在那个地方?
推荐答案
直接从 Apple :NSNull类定义了一个单例对象,用于在nil被禁止作为值(通常在诸如数组或字典的集合对象)的情况下用于表示空值。
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)."
所以在你的例子中,这正是发生的事情,程序员正在选择将一个空对象放入控制器数组,其中nil不允许作为值。
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.
这篇关于[NSNull null]和nil有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文