码迷,mamicode.com
首页 > 其他好文 > 详细

NSNull的用法和原理

时间:2015-05-06 14:46:39      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

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");
        }
    }

NSNull的用法和原理

标签:

原文地址:http://www.cnblogs.com/NSNULL/p/4481606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!