Coder Social home page Coder Social logo

dymodelmaker's Introduction

DYModelMaker

中文说明

安装

使用 cocoapods

pod 'DYModelMaker'    

用法

目前提供了两类方法: 1.字典生成模型,支持多层模型嵌套,自动生成两种框架(MJExtension和YYModel)的系统关键字替换和数组中字典转模型代码,导入#import "NSObject+DYModelMaker.h"自动实现归档、解档,直接存取模型即可 dicImg

生成的结果

 
====================@interface==================

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


@interface DYTestModel : NSObject
@property (nonatomic, strong) NSNumber *testModelId;
@property (nonatomic, strong) DataModel *data;
@end

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

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

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

====================@implementation====================

@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

2.模型间赋值操作:

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

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

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

[NSObject assignmentModel:model0 toModel:model1]; 

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

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

DYTestModel *model1 = [NSObject 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];
[NSObject combineModelWithModel1:model0 model2:model1 toModel:model2];

dymodelmaker's People

Contributors

duyi56432 avatar

Watchers

James Cloos avatar JQ.MrHuang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.