//联系人:石虎QQ: 1224614774昵称:嗡嘛呢叭咪哄
一、封装和拆包的概念
我们将C和OC中的基本数据类型(值类型)转换成对象(引用类型)的过程,叫做封装。
相对应的也有一个将对象转变成基本数据类型,此过程叫做拆包。
功能:将OC和C当中的基本数据类型转换成实例对象,即将'值类型'转换成'引用类型'
二、NSValue类型封装、拆包
1.NSRange包含了两个成员,location以及length。location表示起始位置,以0开始;length表示长度
SRange range = {11,4};
CGPointpoint =CGPointMake(1,2);
CGSizesize =CGSizeMake(3,4);
CGRectrect =CGRectMake(3,4,5,6);
NSRangerange =NSMakeRange(11,4);
NSEdgeInsetsedgeInsets = NSEdgeInsetsMake(11,11,11,11);
2.NSValue为NSNumber的父类
其中NSValue可以将CGPoint,CGSize,CGRect,NSRange,NSEdgeInsets转换成对象
NSValue*pointVa = [NSValuevalueWithPoint:point];
NSValue*sizeVa = [NSValuevalueWithSize:size];
NSValue*rectVa = [NSValuevalueWithRect:rect];
NSValue*rangeVa = [NSValuevalueWithRange:range];
NSValue*edgeInsetsVa = [NSValue valueWithEdgeInsets:edgeInsets];
3.拆包
CGPointpoint1 = [pointVa pointValue];
CGSizesize1 = [sizeVa sizeValue];
CGRectrect1 = [rectVa rectValue];
NSRangerange1 = [rangeVarangeValue];
NSEdgeInsetsedgeInsets1 = [edgeInsetsVa edgeInsetsValue];
三、NSNumber类型封装、拆包
1.OC中常用的数据类型
inta =6;
floatb =6.0;
doublec =6.6;
chard ='a';
boolflag =YES;
2.其中NSNumber可以将'int','float','double','char','bool'等C中基本数据类型转换成对象
NSNumber*intNumber = [NSNumbernumberWithInt:a];
NSNumber*floatNumber = [NSNumbernumberWithFloat:b];
NSNumber*doubleNumber = [NSNumbernumberWithDouble:c];
NSNumber*charNumber = [NSNumbernumberWithChar:d];
NSNumber*boolNumber = [NSNumbernumberWithBool:flag];
3.拆包
inta1 = [intNumberintValue];
floatb1 = [floatNumberfloatValue];
doublec1 = [doubleNumberdoubleValue];
chard1 = [charNumbercharValue];
boolflag1 =[boolNumberboolValue];