WWModel 1.1.1

WWModel 1.1.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年7月

waiwaib 维护。



WWModel 1.1.1

  • 作者
  • waiwaib

WWModelMaster

Model 提供了一个轻量级的 model 基类;支持多种数据格式;具有良好的 model 嵌套支持;

WWDatabase 提供了数据库连接与 sql 执行的公共入口;

modelAssociateDB model 对象使用 sqlite 持久化的操作;

使用示例

Ⅰ.WWModel 安装

pod 'WWModel'

Ⅱ.WWModel 简介

1.model 使用

testModel 继承自 model;

NSDictionary * test = @{@"name":@"waiwai",@"age":@22,@"livePlace":@"中国南京",@"sex":@1};

testModel * model1 = [[testModel alloc]init];

[model1 setValuesForKeysWithDictionary:test];

[model1 display];

输出: 2015-09-29 17:05:09.573 WWModelMaster[3721:172393] 赋值:testModel-->出现多余数据 key:sex value:1

2015-09-29 17:05:09.574 WWModelMaster[3721:172393] testModel

name-->waiwai age-->22 livePlace-->中国南京

拥有完善的异常 key 检测机制

实现了 model 对象的 NSCopying,NSMutableCopying;

提供多种转换方式;初始化方式;

/**

  • 根据 dictionary 初始化 model *
  • @param dictionary 设置参数字典,json 结构; *
  • @return model 对象 / -(instancetype) initWithDictionary:(NSDictionary *)dictionary;

/**

  • 根据 nsdata 初始化 model *
  • @param data json 格式 NSData *
  • @return model 对象 / -(instancetype) initWithData:(NSData *)data;

/**

  • 根据 json String 初始化 model *
  • @param string json String *
  • @return model 对象 */ -(instancetype) initWithJsonString:(NSString *)string;

/**

  • model 对象转字典 *
  • @return 结果 NSDictionary / -(NSDictionary *) toDictionary;

-(NSDictionary *) toDictionaryWithKeys:(NSArray *)propertyNames;

/**

  • model 对象转 NSData *
  • @return 结果 NSData / -(NSData *) toData;

-(NSData *) toDataWithKeys:(NSArray *)propertyNames;

/**

  • model 对象转 json String *
  • @return json 格式 NSString */ -(NSString *) toJsonString;

-(NSString *) toJsonStringWithKeys:(NSArray *)propertyNames;

同样具有完善的异常处理机制;

dictionarys 和 models 互相转换

NSDictionary * test = @{@"name":@"waiwai",@"age":@22,@"livePlace":@"中国南京"};

NSDictionary * test1 = @{@"name":@"huihui",@"age":@20,@"livePlace":@"中国南京"};

NSArray * models = [testModel modelsWithDictionarys:@[test,test1]];

NSDictionary * dicts = [testModel dictionarysWithModels:models convertKeys:@[@"name"]];

2.WWDatabase 介绍

提供了 WWDatabase,提供了数据库连接与 sql 执行的公共入口;

独立模块,可以单独使用 WWDatabase 来实现自己的更多需求数据库功能;

3.modelAssociateDB 介绍

这里提供了 model 连接 WWDatabase 使用 sqlite 实现数据持久化的方案;

  • (BOOL)saveModel:(id) model;

  • (BOOL)deleteModel:(id) model;

  • (BOOL)updateModel:(id) newModel;

  • (NSArray *)selectAll:(NSString *) tableName;

提供基本的增加、删除、更新、查询函数;

  • (BOOL)deleteWithModelTable:(NSString *)tableName where:(NSDictionary *)where;

  • (BOOL)updateWithModelTable:(NSString *)tableName Content:(NSDictionary *)updateContent where:(NSDictionary *)where;

  • (NSArray *)selectWithModelTable:(NSString *)tableName where:(NSDictionary *)where groupBy:(NSString *)group;

  • (id)findWithModelTable:(NSString *)tableName withPrimary:(NSUInteger)primary;

提供了复杂的增加、删除、更新、查询函数。

提供了使用示例;一个简单的通讯录应用。