向 NSArray NSDictionary 中添加数字、自定义结构体等

来源:互联网 发布:url端口号 编辑:程序博客网 时间:2024/06/03 21:25

转载自:http://www.dreamingwish.com/dream-2011/add-to-nsarray-nsdictionary-digital-custom-structures-etc.html

添加数字,用nsnumber类:

//转换为NSNumber+ (NSNumber *)numberWithInt:(int)value- (id)initWithInt:(int)value//转换回数字- (int)intValue

添加结构体,用nsvalue类:

typedef struct {NSUInteger line;NSUInteger row;} TileLocation;//转换为NSValueNSValue *value = [NSValue valueWithBytes:&tileLoc objCType:@encode(TileLocation)];//转换回结构体TileLocation loc;[value getValue:&loc];