OC 封装 拆包 基本数据类型.
NSValue /NSNumber
功能:将OC 和C 当中的基本数据类型转换成实例对象,即值类型 转换 引用类型..
CGPoint point =CGPointMake(3, 4);
CGSize size =CGSizeMake(5, 6);
CGRect rect = CGRectMake(3, 4, 5, 6);
NSRange range = NSMakeRange(10, 3);
NSEdgeInsets edgeInsete =NSEdgeInsetsMake(10, 10, 10, 10);
// NSValue
//其中NSValue 可以将 CGpoint CGSize CGRrct NSRange NSEdgeInsets 转换成对
NSValue *PointVa =[NSValue valueWithPoint:point ];
NSValue *sizaVa =[NSValue valueWithSize:size];
NSValue *rectVa = [NSValue valueWithRect:rect];
NSValue *rangeVa = [NSValue valueWithRange:range];
NSValue *edgeVa = [NSValue valueWithEdgeInsets:edgeInsete];
CGPoint point1 = [PointVa pointValue];
CGSize siza1 = [sizaVa sizeValue];
CGRect rect1 = [rectVa rectValue];
NSRange range1 =[rangeVa rangeValue];
NSEdgeInsets edgeInsete1 =[edgeVa edgeInsetsValue];
2.字符串
字符串分为: 不可变字符串 与 可变字符串
NSString 不可变字符串
//1.初始化一个字符串对象
NSString *string1 =[NSString stringWithFormat:@"Jack"];
//使用NSString 的类方法来创建字符串 +(instancetype)stringWithFormat:@"格式化标识符"
NSString *string2 = [NSString stringWithFormat:@"%@,%d,%f,hi guy",@"Rick",5,5.5];
NSLog(@"string2 = %@",string2);
NSString *string3 =@"Rick";
NSString *string4 =@"6";
NSString *string5 =[NSString stringWithFormat:@"%@ %@",string3,string4];
NSLog(@"string5 = %@",string5);
//从本地文件读取字符串
NSString *panth1 =@"/Users/Macx/Desktop/OC练习/OC_04_02/OC_04_02/hello.html";
NSError *error;
NSString *string6 =[NSString stringWithContentsOfFile:panth1 encoding:4 error:&error];
//从网络读取字符串
NSURL *url =[NSURL URLWithString:@"http://www.baidu.com"];
error =nil;
NSString *string7 =[NSString stringWithContentsOfURL:url encoding:4 error:&error];
NSLog(@"string7 = %@",string7);
//字符串的操作
NSString *string8=@"你是逗逼啊,我真受不了你了";
//字符串的长度
NSInteger length =[string8 length];
//字符串的截取
NSString *subString1 =[string8 substringToIndex:5]; //ToIndex不包括5
NSString *subString2 =[string8 substringFromIndex:6];//FromIndex从6开始
NSString *subString3 =[string8 substringWithRange:NSMakeRange(2, 2)];
可变字符串~~!
// NSMutableString 可变字符串
NSMutableString * mString =[NSMutableString stringWithString:@"nihao"];
NSMutableString *mString1 =[NSMutableString stringWithFormat:@"%@",mString];
NSMutableString *mString2 = [NSMutableString stringWithContentsOfFile:@"" encoding:4 error:nil];
NSMutableString *String3= [NSMutableString stringWithContentsOfURL:[NSURL URLWithString:@""] encoding:4 error:nil];
//可变字符串独特的初始化方法,初始化一个空间为100的可变字符串
NSMutableString *mString4 =[[NSMutableString alloc]initWithCapacity:100];
NSMutableString * targeString = [NSMutableString stringWithString:@"呵呵,你好"];
//增
//在指定位置去插入一个字符串
[targeString insertString:@"我去" atIndex:3];
//在字符串末尾添加一个字符串
[targeString appendString:@",你傻了"];
//在字符串的末尾添加多个字符串
[targeString appendFormat:@"%@ %@",@"拜拜",@"哈哈"];
//删
[targeString deleteCharactersInRange:NSMakeRange(3, 2)];