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

添加数字,用NSNumber类:

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

添加结构体,用nsvalue类:

typedef struct {  
    NSUInteger line;  
    NSUInteger row;  
} TileLocation;  

//转换为NSValue  
NSValue *value = [NSValue valueWithBytes:&tileLoc objCType:@encode(TileLocation)];  
//转换回结构体  
TileLocation loc;  
[value getValue:&loc];

 

posted @ 2016-05-11 13:22  niwanglong385  阅读(527)  评论(0)    收藏  举报