代码改变世界

NSNull与nil

2017-11-27 13:46  dengchaojie_learner  阅读(174)  评论(0编辑  收藏  举报

    NSDictionary *dictNull = @{@"key":[NSNull null]};

 

    NSDictionary *dictNil = @{@"key":nil};//Collection element of type 'void *' is not an Objective-C object

 

 

 

 

 

    NSMutableDictionary *dict = [NSMutableDictionary dictionary];

    [dict setValue:nil forKey:@"keyNil"];

    [dict setObject:[NSNull null] forKey:@"keyNull"];

/* Send -setObject:forKey: to the receiver, unless the value is nil, in which case send -removeObjectForKey:.

*/

- (void)setValue:(nullable ObjectType)value forKey:(NSString *)key;

 

 

- (void)setObject:(ObjectType)anObject forKey:(id<NSCopying>)aKey;

Important

Raises an NSInvalidArgumentException if anObject is nil. If you need to represent a nil value in the dictionary, use NSNull.