代码拉取完成,页面将自动刷新
To run the example project, clone the repo, and run pod install
or 'pod update' from the Example directory first.
1: 创建一个继承LYJArchiveModel的类UserModel,UserModel放入我们的使用的属性(支持的格式NSString, NSInteger, double, NSDictionary, NSArray, NSMutableDictionary, NSMutableArray, CGFloat, NSData, 继承LYJArchiveModel的类 , UIImage)
2: 在 UserModel 创建你自己使用到的属性
例如:
#import "ArciveModel.h"
@class SubUserModel , UIImage;
@interface UserModel : ArciveModel
@property (nonatomic , copy) NSString *name;
@property (nonatomic , assign) BOOL isFirstLogin;
@property (nonatomic , assign) NSInteger age;
@property (nonatomic , assign) double height;
@property (nonatomic , strong) NSDictionary *dic;
@property (nonatomic , strong) NSArray *arr;
@property (nonatomic , strong) SubUserModel *subUserModel; // 继承LYJArchiveModel的子类
@property (nonatomic , strong) UIImage *userImage;
@end
3: 使用方法
在控制器中引入头文件: #import <LYJArchiveModel/LYJArchiveModel-umbrella.h>
UserModel *model = [UserModel new];
model.name = @"你好";
model.isFirstLogin = YES;
model.age = 18;
model.height = 181.5;
model.dic = @{@"1" : @"2"};
model.arr = @[@"4" , @"5"];
model.userImage = [UIImage imageNamed:@"123"];
model.subUserModel = [SubUserModel new];
model.subUserModel.name = @"你浪开";
model.subUserModel.age = 20;
model.subUserModel.isFirstLogin = YES;
model.subUserModel.height = 170.1;
// 如果归档时间较长,这里开启加载动画
if ([UserModel archive:model keyName:@"li"]) { // 这里开始归档并存储到本地,如果存储成功继续往下执行
model = nil; // 这里置空,为了演示使用>
// 储存完成后
// 这里关闭加载动画
}
NSLog(@"Model name is %@" , model.name);
UserModel *newModel = [UserModel unarchiveWithKeyName:@"li"]; // 取出本地存储的数据,并进行解档
if (newModel.isFirstLogin) {
NSLog(@"model.name is %@" , newModel.name);
NSLog(@"%ld", newModel.age);
NSLog(@"%.2f" , newModel.height);
NSLog(@"dic is %@" , newModel.dic);
self.photoImageView.image = newModel.userImage;
}
if (newModel.subUserModel.isFirstLogin) {
NSLog(@"Info of subUserModel is %@ , %ld , %.2f" , newModel.subUserModel.name , newModel.subUserModel.age , newModel.subUserModel.height);
}
输出结果:
Model name is (null)
model.name is 你好
18
181.50
dic is {
1 = 2;
}
Info of subUserModel is 你浪开 , 20 , 170.10
LYJArchiveModel is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'LYJArchiveModel'
li625317534, 625317534@qq.com
LYJArchiveModel is available under the MIT license. See the LICENSE file for more info.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。