Skip to content

辅助对象持久化,归档,序列化/反序列化

License

Notifications You must be signed in to change notification settings

ZeroFengLee/ZObjcStore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZObjcStore

Version License Platform

ZObjcStore是一个轻量级的对象存储框架。

适用于

假如你的项目当中有很多的零散信息需要持久化,数据量少,但是分散。还不至于使用数据库这种庞大的存储框架的时候,ZObjcStore也许非常适合你

特性

  • 持久化支持多用户
  • 对象之间的归档互不影响
  • 存储操作简单,再也不需要去编写序列化/反序列化的机械操作

安装

###Podfile 在podfile中添加ZObjcStore依赖

pod 'ZObjcStore', '~> 1.0.2'

然后运行pod 更新

$ pod install

使用

###基础用法

导入头文件

#import <ZObjcStore/ZCodingSupport.h>   
#import <ZObjcStore/ZObjcStore.h>   
定一个Student模型

注意: 存储的Model类一定要继承ZCodingSupport

@interface Student : ZCodingSupport

@property (nonatomic, strong) NSString *name;

@property (nonatomic, assign) int age;

@end
更新整个Model
+ (void)updateStudent:(Student *)stu {
    [ZobjcStore saveInfo: stu];
}
获取整个Model
+ (Student *)getStudent:(Class)cls {
    return [ZobjcStore getInfo: cls];
}
更新用户信息
//更新用户名
+ (void)updateStudentName:(NSString *)name {
    [ZObjcStore update:[Student class] value:name key:@"name"];
}
获取用户信息
+ (NSString *)studentName {
    return [ZObjcStore get:[Student class] key:@"name"];
}

进阶用法

我们上面已经存储量用户的相关信息,但是每个用户的信息是不一样的,App由`User_A`切换到了`User_B`账户,B账户肯定不需要A账户的存储信息,而且当`User_B`再切回`User_A`的时候,项目要保证A账户的信息还在。

这个时候,你可以考虑使用ZObjcStore的分管理用户存储功能 handleContext , handleContext方法可以在不同管理用户间快速切换,但是注意,同一时间只能存在一个管理用户。

+ (void)handleContext:(NSString *)userId {
    [ZObjcStore handleContext:userId];
}

About

辅助对象持久化,归档,序列化/反序列化

Resources

License

Stars

Watchers

Forks

Packages

No packages published