当前位置: 首页 > news >正文

建五金方面的网站免费网络爬虫网站

建五金方面的网站,免费网络爬虫网站,1040视频app,专线网站建设1、NSData归档多个对象 一、之前我写的学习笔记都是归档一个对象#xff0c;如果需要归档多个对象我们需要借助NSData 二、步骤 1#xff09;、NSMutableData作为参数#xff0c;构建 NSKeyedArchiver对象 2#xff09;、调用NSKeyedArchiver的encodeXXX 3)、调用NSKeyed…1、NSData归档多个对象 一、之前我写的学习笔记都是归档一个对象如果需要归档多个对象我们需要借助NSData 二、步骤 1、NSMutableData作为参数构建 NSKeyedArchiver对象 2、调用NSKeyedArchiver的encodeXXX 3)、调用NSKeyedArchiver的finishEncoding方法  4)、NSMutableData保存到文件 2、归档对象实现深复制 我们知道深复制就是复制对象和原始对象没有任何公用的部分修改复制对象的值不会对原始对象产生影响。 步骤 1、NSKeyedArchiver的archivedDataWithRootObject 2、NSKeyedUnarchiver的unarchiveObjectWithData 3、实现Demo IApple.h #import Foundation/Foundation.h #ifndef IApple_h #define IApple_h interface IApple : NSObject NSCoding property (nonatomic, copy) NSString *color; property (nonatomic, assign) double weight; property (nonatomic, assign) int size; -(id)initWithColor:(NSString *) color weight:(double) weight size:(int) size; end#endif /* IApple_h */ IApple.m #import IApple.h #import Foundation/Foundation.h implementation IApple synthesize color _color; synthesize weight _weight; synthesize size _size; -(id)initWithColor:(NSString *) color weight:(double) weight size:(int) size {if (self [super init]){self.color color;self.weight weight;self.size size;}return self; } -(NSString *)description {return [NSString stringWithFormat:IApple [color %, weight %g, _size %d], self.color, self.weight, self.size]; }-(void)encodeWithCoder:(NSCoder *)aCoder {[aCoder encodeObject:_color forKey:color];[aCoder encodeDouble:_weight forKey:weight];[aCoder encodeInt:_size forKey:size]; } -(id) initWithCoder:(NSCoder *)aDecoder {_color [aDecoder decodeObjectForKey:color];_weight [aDecoder decodeDoubleForKey:weight];_size [aDecoder decodeIntForKey:size];return self; }endmain.m #import IApple.h int main(int argc, char * argv[]) {autoreleasepool {NSDictionary *dict [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:80], java, [NSNumber numberWithInt:90], c, [NSNumber numberWithInt:70], oc, [NSNumber numberWithInt:100], c,nil];NSSet *set [NSSet setWithObjects:java, ios, c, oc, nil];IApple *apple [[IApple alloc] initWithColor:red weight:50 size:20];NSMutableData *data [NSMutableData data];NSKeyedArchiver *arch [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];//归档对象[arch encodeObject:dict forKey:dict];[arch encodeObject:set forKey:set];[arch encodeObject:apple forKey:apple];//结束归档[arch finishEncoding];//在document目录下创建一个chenyu.txt空文件NSArray *docPaths NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *path [docPaths objectAtIndex:0];NSLog(document path:%, path);NSFileManager *fileManager [NSFileManager defaultManager];NSString *chenyuPath [path stringByAppendingPathComponent:chenyu.txt];BOOL isSuccess [fileManager createFileAtPath:chenyuPath contents:nil attributes:nil];if (isSuccess) {NSLog(make chenyu.txt success);} else {NSLog(make chenyu.txt fail);}//归档对象到chenyu.txt文件if([data writeToFile:chenyuPath atomically:YES] YES){NSLog(归档对象成功);}else{NSLog(归档对象失败);}//读取归档对象NSData *readData [NSData dataWithContentsOfFile:chenyuPath];NSKeyedUnarchiver *unArch [[NSKeyedUnarchiver alloc] initForReadingWithData:readData];NSDictionary *readDict [unArch decodeObjectForKey:dict];NSSet *readSet [unArch decodeObjectForKey:set];NSSet *readApple [unArch decodeObjectForKey:apple];NSLog(readDict is:%, readDict);NSLog(readSet is:%, readSet);NSLog(readApple is %, readApple);//使用归档对戏实现深复制 深复制就是复制对象和本身对象没有任何公用部分所以修改复制对象的属性不会影响原始对象的属性NSDictionary *diction [NSDictionary dictionaryWithObjectsAndKeys:[[IApple alloc] initWithColor:red weight:50 size:20], one, [[IApple alloc] initWithColor:green weight:60 size:21], two, nil];//对象归档NSData *data1 [NSKeyedArchiver archivedDataWithRootObject:diction];//回复对象NSDictionary *dictCopy [NSKeyedUnarchiver unarchiveObjectWithData:data1];IApple *app [dictCopy objectForKey:one];[app setColor:green];IApple *app1 [diction objectForKey:one];NSLog(app1 color is:%, app1.color);} } 4、运行结果 2018-07-22 19:34:11.2588160800 cyTest[62704:16613816] document path:*****/3FF9B833-FAF8-4C30-A855-3D40A4EAE8A6/data/Containers/Data/Application/6AD520C9-3A99-45B5-A2F9-4E4D7CA77486/Documents 2018-07-22 19:34:11.2695390800 cyTest[62704:16613816] make chenyu.txt success 2018-07-22 19:34:11.2718980800 cyTest[62704:16613816] 归档对象成功 2018-07-22 19:34:11.2729760800 cyTest[62704:16613816] readDict is:{c 90;c 100;java 80;oc 70; } 2018-07-22 19:34:11.2732430800 cyTest[62704:16613816] readSet is:{(c,java,ios,oc )} 2018-07-22 19:34:11.2736020800 cyTest[62704:16613816] readApple is IApple [color red, weight 50, _size 20] 2018-07-22 19:34:11.2741500800 cyTest[62704:16613816] app1 color is:red
http://www.yutouwan.com/news/143339/

相关文章:

  • 南宁网络营销网站设计专业干货推荐网站
  • 盐城网站建设找宇农村未来10大暴利行业
  • 做粤菜的视频网站银行服务外包公司排名
  • wap小说网站源码网站设计与开发培训班
  • 如何制作单页网站现在出入深圳最新规定
  • net网站开发的步骤txt什么是网络营销?它包括了哪些主要环节?
  • 北京网站制作公司排名wordpress 调用百度地图吗
  • 网站地图在线制作工具怎样建公司网站
  • 给别人做网站是外包公司全国招聘网最新招聘信息
  • 做能收款的网站多少钱推广网络营销外包公司
  • 美容院门户网站开发学做网站从前端到后端
  • 免费手机h5模板网站模板儋州网站建设制作
  • 免费做淘宝联盟网站北京网站建设交易
  • vps看网站蜘蛛学生作品网网站
  • 简单的个人网站模板做网站的图片房产
  • 怎么制作网站论坛模板青岛硅谷网站建设公司
  • 上海做网站的多吗企业网站wap源码
  • 怎么优化网站的单个关键词排名企业网页设计模板图片
  • 浙江省工程建设质量管理协会 网站丰台网站建设
  • 电子商务网站建设方式济南市建设工程招投标协会网站
  • 网站建设目标及需求网站被入侵
  • 在线做效果图的网站有哪些成都企业网站建设那家好
  • 网站设网站设计阳江房产网二手房出售
  • 网站建设制作及推广网页设计模板素材简单
  • 如何自己创网站建个电子商务网站多少钱
  • asp网站网站建设与品牌策划方案报价
  • 精品课程网站建设毕业设计做网站内容
  • php 公司网站做竞价的网站可以做优化吗
  • 深圳市门户网站建设企业wordpress 微博文章
  • 中信建设有限责任公司网站抖音推广引流方式