首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

NSNull功用

2012-06-26 
NSNull作用Directly from?Apple: The NSNull class defines a singleton object you use to represent nu

NSNull作用

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)."

?

NSNull表示一个为空值的一个对象,使用的一个例子:

NSMutableArray *controllers = [[NSMutableArray alloc] init];for (unsigned i = 0; i < kNumberOfPages; i++) {    [controllers addObject:[NSNull null]];
?在Objective-c中,对于像NSArray这样的类型,nil或NULL不能做为加到其中的Object,如果定义了一个NSArray,为其分配了内存,又想设置其中的内容为空,则可以用[NSNULL null返回的对对象来初始化NSArray中的内容

热点排行