- model.h 实现协议<NSCoding,NSSecureCoding>
@interface UserModel : NSObject<NSCoding,NSSecureCoding>
.....
@end
- model.m 配合MJExtension实现coding,最重要的 多写一个支持NSSecureCoding
@implementation UserModel
MJCodingImplementation
///ios11+必须实现
+(BOOL)supportsSecureCoding{
return YES;
}
@end
- 使用
///存
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user requiringSecureCoding:YES error:nil];
///取
[NSKeyedUnarchiver unarchivedObjectOfClass:[UserModel class] fromData:data error:&err];
网友评论