ios开发 - MJExtension
学习链接:
https://www.jianshu.com/p/7e8af12ab5a4
https://www.jianshu.com/p/b4a1956f7578
总结:
场景:
假设我想存储 类A 至缓存,并在某时机要读这个数据
一般用法:
1、A类 #import <MJExtension/MJExtension.h>
2、@implementation A
MJExtensionCodingImplementation
存储
3、NSData *data = [NSKeyedArchiver archivedDataWithRootObject:A实例];
4、[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"key"];
读取
5、NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"key"];
if (data){
A实例 = [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
当初的梦想实现了吗,事到如今只好放弃吗~