[简书](http://www.jianshu.com)
<p>单一段落
二级标题
三级标题
多行。
学习,进阶阶段。
学习,苦闷阶段。
学习,放弃阶段。
<br />
- 星号
- 列表
- 列表2
- 列表3
Tables | Are | Cool |
---|---|---|
col 3 is | right-aligned | $1600 |
col 2 is | centered | $12 |
zebra stripes | are neat | $1 |
作者:Te_Lee
链接:http://www.jianshu.com/p/1e402922ee32/
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
链接
保存归档文件
- (void)saveInfo{
NSString * path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
NSString *filePath = [path stringByAppendingString:NSStringFromClass([AutoEncode class])];
NSLog(@"%@",filePath);
[NSKeyedArchiver archiveRootObject:self toFile:filePath];}
自动归档解档
#import <objc/runtime.h>
/**
* 存
*
* @param
* @param
* @param
*/
- (void)encodeWithCoder:(NSCoder *)aCoder{
unsigned int count = 0 ;
Ivar * ivars = class_copyIvarList([AutoEncode class], &count);
for (int i = 0 ; i < count ; i++) {
Ivar ivar = ivars[i];
const char * name = ivar_getName(ivar);
NSString * key = [NSString stringWithUTF8String:name];
id value = [self valueForKey:key];
[aCoder encodeObject:value forKey:key];
}
free(ivars);
}
/**
* 取
*
* @param
* @param
* @param
*/
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
if (self = [super init]) {
unsigned int count = 0;
Ivar * ivars = class_copyIvarList([AutoEncode class], &count);
for (int i = 0; i < count; i++) {
Ivar ivar = ivars[i];
const char * name = ivar_getName(ivar);
NSString * key = [NSString stringWithUTF8String:name];
id value = [aDecoder decodeObjectForKey:key];
[self setValue:value forKey:key];
}
free(ivars);
}
return self;
}