添加数字,用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];

本文介绍了如何在Objective-C中将基本整型数值转换为NSNumber对象,并演示了如何将自定义结构体类型通过NSValue进行封装及解封装的过程。
1105

被折叠的 条评论
为什么被折叠?



