标签:
Represent nil with NSNull
It’s not possible to add nil to the collection classes described in this section because nil in Objective-C means “no object.” If you need to represent “no object” in a collection, you can use the NSNull class:
NSArray *array = @[ @"string", @42, [NSNull null] ];
NSNull is a singleton class, which means that the null method will always return the same instance. This means that you can check whether an object in an array is equal to the shared NSNull instance:
for (id object in array) {
if (object == [NSNull null]) {
NSLog(@"Found a null object");
}
}
标签:
原文地址:http://www.cnblogs.com/NSNULL/p/4481606.html