向nsarray nsdictionary中添加数字、自定义结构体等
添加数字,用nsnumber类:
//转换为NSNumber
+ (NSNumber *)numberWithInt:(int)value
- (id)initWithInt:(int)value
//转换回数字
- (int)intValue
添加结构体,用nsvalue类:
typedef struct {
NSUInteger line;
NSUInteger row;
} TileLocation;
//转换为NSValue
NSValue *value = [NSValue valueWithBytes:&tileLoc objCType:@encode(TileLocation)];
//转换回结构体
TileLocation loc;
[value getValue:&loc];
ps: nsarray中可以使用nsnull来作为占位因为不能使用nil和null作为占位的缘故
转载于:https://blog.51cto.com/derkin2jessie/1151543