1.序列化和不序列化直接写入文件,前后文件size相差巨大,大约压缩70%。
NSArray * arr = @[@"jhfiwe",@"kuwi",@"oiu",@"jeygri",@"eyriow",@"klwurpwiqh",@"lwurifb",@"lkwurgfuwbc",@"keuhfi",@"klrtgiowv"];
NSArray * doucments = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * path = [doucments objectAtIndex:0];
//数组直接写入文件
NSString * arryPathUn = [NSString stringWithFormat:@"%@/unxlh.text",path];
[arr writeToFile:arryPathUn atomically:YES];
//序列化后写入
NSString * error;
NSString * xlhPath = [NSString stringWithFormat:@"%@/xlh.text",path];
NSData * data = [NSPropertyListSerialization dataWithPropertyList:arr format:NSPropertyListBinaryFormat_v1_0 options:0 error:&error];
[data writeToFile:xlhPath atomically:YES];
本文介绍了一种在iOS开发中使用NSArray进行序列化的方法,通过对比直接将数组写入文件与序列化后再写入文件的方式,发现后者能够显著减小文件大小,达到约70%的压缩效果。
3157

被折叠的 条评论
为什么被折叠?



