NSValue 使用如下:
#import "MS_NSValue.h"
#import "MS_NSNumber.h"
@implementation MS_NSValue
@synthesize _nsValue;
-(void)showNSValue
{
//使用NSValue存储 c 字符串
char *cString = "This is C string";
NSValue *value1 = [[NSValue alloc] initWithBytes:&cString objCType:@encode(char *)];
char *cString1;
[value1 getValue:&cString1];
NSLog(@"Get cString1:%s",cString1);
char *cString2 = "This is C string2";
NSValue *value2 = [[NSValue alloc] initWithBytes:&cString2 objCType:@encode(char **)];
char *cString2Temp;
[value2 getValue:&cString2Temp];
NSLog(@"Get cString2:%s",cString2Temp);
//存储NSString 字符串
NSString *nsString1 = @"This is NSString1";
NSValue *value3 = [[NSValue alloc] initWithBytes:&nsString1 objCType:@encode(NSString *)];
NSString *nsString1Temp ;
[value3 getValue:&nsString1Temp];
NSLog(@"Get NSString1:%@",nsString1Temp);
//存储int 基本数据类型
int number1 = 2;
NSValue *value4 = [[NSValue alloc] initWithBytes:&number1 objCType:@encode(int)];
int number1Temp;
[value4 getValue:&number1Temp];
NSLog(@"Get int1:%i",number1Temp);
}
@end