// NSValue可以将c类型转换为Objective-C对象,如NSRange,CGPoint,CGSize,CGRect,CGVector,UIEdgeInsets,UIOffset NSRange range = NSMakeRange(0, 1); NSValue *rangeValue = [NSValue valueWithRange:range]; // NSValue转换NSRange NSRange valueToRange = [rangeValue rangeValue]; // 自定义的结构体 typedef struct {char *name; float score;} Student; Student studentA = {"xiao ming", 85.0}; NSValue *studentValue = [NSValue value:&studentA withObjCType:@encode(Student)]; // NSValue转换Student Student valueToStudent ; [studentValue getValue:&valueToStudent];
objective-c 中数据类型之六 数值类(NSValue)
原文地址:http://blog.csdn.net/yanglishuan/article/details/39992529