{"id":475,"date":"2014-11-05T23:40:35","date_gmt":"2014-11-05T15:40:35","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=475"},"modified":"2016-07-15T17:22:38","modified_gmt":"2016-07-15T09:22:38","slug":"ios%e5%bc%80%e5%8f%91%e4%b8%ad%e5%a4%9a%e5%af%b9%e8%b1%a1%e5%bd%92%e6%a1%a3%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2014\/11\/05\/234035475.html","title":{"rendered":"iOS\u5f00\u53d1\u4e2d\u591a\u5bf9\u8c61\u5f52\u6863\u64cd\u4f5c"},"content":{"rendered":"<p>1\u3001NSData\u65b9\u5f0f\u591a\u5bf9\u8c61\u5f52\u6863<\/p>\n<pre lang=\"objc\" line=\"1\">    \/\/ 1\u3001\u521b\u5efa\u5f52\u6863\u8def\u5f84\n    NSString *dataPath = [documentsPath stringByAppendingPathComponent:@\"data.plist\"];\n    \/\/ 2\u3001\u521b\u5efa\u53ef\u53d8\u6570\u636e\u5bf9\u8c61\n    NSMutableData *data = [NSMutableData data];\n    \/\/ 3\u3001\u521b\u5efa\u5f52\u6863\n    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];\n    \/\/ 4\u3001\u5f52\u6863\u4e2d\u6dfb\u52a0\u5bf9\u8c61\u5143\u7d20\n    [archiver encodeObject:array forKey:@\"array\"];\n    [archiver encodeObject:dict forKey:@\"dict\"];\n    [archiver encodeObject:string forKey:@\"string\"];\n    [archiver encodeObject:imageData forKey:@\"image\"];\n    \/\/ 5\u3001\u7ed3\u675f\u5f52\u6863\n    [archiver finishEncoding];\n    \/\/ 6\u3001\u5199\u5165\u672c\u5730\u6c99\u76d2\n    [data writeToFile:dataPath atomically:YES];\n    \/\/ 7\u3001\u53d6\u51fa\u5f52\u6863\u5373\u89e3\u6863\n    NSData *data1 = [NSData dataWithContentsOfFile:dataPath];\n    NSKeyedUnarchiver *unarchive1 = [[NSKeyedUnarchiver alloc] initForReadingWithData:data1];\n    \/\/ 8\u3001\u8fd8\u539f\u5404\u5bf9\u8c61\n    NSArray *array1 = [unarchive1 decodeObjectForKey:@\"array\"];\n    NSDictionary *dict1 = [unarchive1 decodeObjectForKey:@\"dict\"];\n    NSString *string1 = [unarchive1 decodeObjectForKey:@\"string\"];\n    UIImage *imag1 = [UIImage imageWithData:[unarchive1 decodeObjectForKey:@\"image\"]];<\/pre>\n<p>2\u3001\u6570\u7ec4\u65b9\u5f0f\u8fdb\u884c\u591a\u5bf9\u8c61\u5f52\u6863<!--more--><\/p>\n<pre lang=\"objc\" line=\"1\">    \/\/ 1\u3001\u521b\u5efa\u5f52\u6863\u8def\u5f84\n    NSString *dataPath2 = [documentsPath stringByAppendingPathComponent:@\"data.array\"];\n    \/\/ 2\u3001\u521b\u5efa\u591a\u5bf9\u8c61\u6570\u7ec4\n    NSArray *arrayArchiver = @[array, dict, string, imageData];\n    \/\/ 3\u3001\u5f52\u6863\u6570\u7ec4\n    [NSKeyedArchiver archiveRootObject:arrayArchiver toFile:dataPath2];\n    \/\/ [arrayArchiver writeToFile:dataPath2 atomically:YES];\n    \/\/ 4\u3001\u53d6\u51fa\u5f52\u6863\u5373\u89e3\u6863\n    NSArray *getArray2 = [NSKeyedUnarchiver unarchiveObjectWithFile:dataPath2];\n    \/\/NSArray *getArray1 = [NSArray arrayWithContentsOfFile:dataPath2];\n    \/\/ 5\u3001\u8fd8\u539f\u6570\u7ec4\u4e2d\u5404\u5bf9\u8c61\n    NSArray *array2 = getArray2[0];\n    NSDictionary *dict2 = getArray2[1];\n    NSString *string2 = getArray2[2];\n    UIImage *image2 = [UIImage imageWithData:getArray2[3]];<\/pre>\n<p><strong>3\u3001\u76f8\u5173\u94fe\u63a5<\/strong><\/p>\n<p>3.1\u3001<a href=\"http:\/\/www.yusian.com\/blog\/project\/2014\/11\/06\/094658.html\" target=\"_blank\">iOS\u5f00\u53d1\u4e2d\u81ea\u5b9a\u4e49\u5bf9\u8c61\u7684\u5f52\u6863<\/a><br \/>\n3.2\u3001<a href=\"http:\/\/www.yusian.com\/blog\/project\/2014\/11\/05\/210124.html\" target=\"_blank\">iOS\u5f00\u53d1\u4e2d\u57fa\u672c\u6587\u4ef6\u8bfb\u5199\u64cd\u4f5c\u793a\u4f8b<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001NSData\u65b9\u5f0f\u591a\u5bf9\u8c61\u5f52\u6863 \/\/ 1\u3001\u521b\u5efa\u5f52\u6863\u8def\u5f84 NSString *dataPath = [documentsPath stringByAppendingPathComponent:@&#8221;data.plist&#8221;]; \/\/ 2\u3001\u521b\u5efa\u53ef\u53d8\u6570\u636e\u5bf9\u8c61 NSMutableData *data = [NSMutableData data]; \/\/ 3\u3001\u521b\u5efa\u5f52\u6863 NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; \/\/ 4\u3001\u5f52\u6863\u4e2d\u6dfb\u52a0\u5bf9\u8c61\u5143\u7d20 [archiver encodeObject:array forKey:@&#8221;array&#8221;]; [archiver encodeObject:dict forKey:@&#8221;dict&#8221;]; [archiver encodeObject:string forKey:@&#8221;string&#8221;]; [archiver encodeObject:imageData forKey:@&#8221;image&#8221;]; \/\/ 5\u3001\u7ed3\u675f\u5f52\u6863 [archiver finishEncoding]; \/\/ 6\u3001\u5199\u5165\u672c\u5730\u6c99\u76d2 [data writeToFile:dataPath atomically:YES]; \/\/ 7\u3001\u53d6\u51fa\u5f52\u6863\u5373\u89e3\u6863 NSData *data1 = [NSData dataWithContentsOfFile:dataPath]; NSKeyedUnarchiver *unarchive1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[20,19],"class_list":["post-475","post","type-post","status-publish","format-standard","hentry","category-project","tag-basics","tag-storage"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=475"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/475\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}