Latest 1.0.1
Homepage https://github.com/duyi56432/DYModelMaker
License MIT
Platforms ios 8.0
Frameworks Foundation
Authors

中文说明

安装

使用 cocoapods

pod ‘DYModelMaker’    
当前最新版本1.0.1,如果不能搜索最新版本,执行命令 pod setup更新pod后再试。

持续优化中,如果有好多建议和意见欢迎交流,QQ群:433212576

博客

这里有更详细用法

简介

@interface XYDHomeBannerModel : NSObject

@property (nonatomic, copy) NSString *imgUrl;

@property (nonatomic, copy) NSString *imgBg;

@property (nonatomic, copy) NSString *linkId;

@end

上面这段代码还在一个一个属性的敲吗?要是有100个字段呢?要是数据结构四五六七层呢?DYModelMaker解放你的双手,一行代码生成所有属性!

对比JSON Accelerator优点:

1.生成常用第三方MJExtension和YYModel的系统关键字替换和数组中字典转模型代码。

2.归档不会生成一大段代码。

3.无需复制接口返回的json去转换。

4.模型头部可以添加关键字。

5.可以使用model间相互转换赋值等方法。

用法

目前提供了两类方法:

一.字典生成模型。

1)支持多层模型嵌套,再也不怕数据结构复杂啦!

2)自动生成两种框架(MJExtension和YYModel)的系统关键字替换和数组中字典转模型代码。

3)导入#import "NSObject+DYModelMaker.h"自动实现归档、解档,直接存取模型即可.

举个栗子:下面这段数据怕不怕?
dicImg

使用DYModelMaker一行搞定

//直接放到网络请求结果调用,生成模型后删除就行,结果打印在控制台
[DYModelMaker DY_makeModelWithDictionary:dic modelKeyword:@"DY" modelName:@"testModel"];

看结果–> 直接复制粘贴就行了

 
[email protected]==================

@class DYTestModel;
@class DYDataModel;
@class DYFlowinfoModel;
@class DYNextFlowIdModel;

@interface DYTestModel : NSObject
@property (nonatomic, copy) NSString *Id;
@property (nonatomic, strong) DYDataModel *data;
@end

@interface DYDataModel : NSObject
@property (nonatomic, copy) NSString *app_id;
@property (nonatomic, copy) NSString *flowTypeId;
@property (nonatomic, copy) NSArray *approveResultValue;
@property (nonatomic, copy) NSArray *flowinfo;
@property (nonatomic, copy) NSString *result;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *level;
@property (nonatomic, copy) NSString *forword_emp_name;
@property (nonatomic, copy) NSString *department;
@property (nonatomic, strong) DYNextFlowIdModel *nextFlowId;
@end

@interface DYFlowinfoModel : NSObject
@property (nonatomic, copy) NSString *day_number;
@property (nonatomic, copy) NSString *Id;
@property (nonatomic, copy) NSString *reason;
@property (nonatomic, copy) NSString *dept_name;
@property (nonatomic, copy) NSString *hour_number;
@property (nonatomic, copy) NSString *time2;
@end

@interface DYNextFlowIdModel : NSObject
@property (nonatomic, copy) NSString *test10;
@end

[email protected]====================

@implementation DYTestModel

+(NSDictionary *)mj_replacedKeyFromPropertyName {
return @{@"Id" : @"id"};

}
@end

@implementation DYDataModel

+ (NSDictionary *)mj_objectClassInArray{
return @{ @"flowinfo" : @"DYFlowinfoModel" }; 
}
@end

@implementation DYFlowinfoModel

+(NSDictionary *)mj_replacedKeyFromPropertyName {
return @{@"Id" : @"id"};

}
@end

@implementation DYNextFlowIdModel

@end

二.模型间赋值操作:

1)将model1 属性名相同的部分赋值给model2,不同部分互不影响

DYTestModel *model0 = [[DYTestModel alloc] init];
model0.testStr = @"testStr0";
model0.testNumber = @10;

DYTest1Model *model1 = [[DYTest1Model alloc] init];
model1.testStr = @"testStr1";

[DYModelMaker assignmentModel:model0 toModel:model1];

2)实现copy,深复制一个model

DYTestModel *model0 = [[DYTestModel alloc] init];
model0.testStr = @"testStr0";
model0.testNumber = @10;

DYTestModel *model1 = [DYModelMaker copyWithModel:model0];

3)将model0 和 model1 合并赋值到model2,model2中和model0、model1不同属性部分互不影响

DYTestModel *model0 = [[DYTestModel alloc] init];
model0.testNumber = @10;

DYTest1Model *model1 = [[DYTest1Model alloc] init];
model1.testStr = @"testStr1";

DYTest2Model *model2 = [[DYTest2Model alloc] init];
[DYModelMaker combineModelWithModel1:model0 model2:model1 toModel:model2];

更新内容

【更新内容】修复模型名称大写被转小写问题。

【更新版本】v1.0.1

【更新时间】2019.4.16

Latest podspec

{
    "name": "DYModelMaker",
    "version": "1.0.1",
    "summary": "u5b57u5178u751fu6210u6a21u578buff0cu652fu6301u591au5c42u6a21u578bu5d4cu5957,u81eau52a8u5b9eu73b0u5f52u6863u3001u89e3u6863,u5b9eu73b0u6a21u578bu76f4u63a5u7684u8d4bu503cu3001u6df1u590du5236",
    "description": "u5b57u5178u751fu6210u6a21u578buff0cu652fu6301u591au5c42u6a21u578bu5d4cu5957,u81eau52a8u751fu6210u4e24u79cdu6846u67b6uff08MJExtensionu548cYYModeluff09u7684u7cfbu7edfu5173u952eu5b57u66ffu6362u548cu6570u7ec4u4e2du5b57u5178u8f6cu6a21u578bu4ee3u7801,u81eau52a8u5b9eu73b0u5f52u6863u3001u89e3u6863,u5b9eu73b0u6a21u578bu76f4u63a5u7684u8d4bu503cu3001u6df1u590du5236",
    "homepage": "https://github.com/duyi56432/DYModelMaker",
    "license": "MIT",
    "authors": {
        "duyi56432": "[email protected]"
    },
    "frameworks": "Foundation",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/duyi56432/DYModelMaker.git",
        "tag": "1.0.1"
    },
    "source_files": "DYModelMaker/**/*.{h,m}"
}

Pin It on Pinterest

Share This