Latest 0.0.1
Homepage https://github.com/AlexCorleone/WQK_Model
License Apache License, Version 2.0 Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Platforms ios , requires ARC
Authors

一个超级简单的字典模型相互转换类。

1.一个超级方便的模型类;

2.支持字典(内包含模型)、数组(内包含模型和字典)、模型转字典;

3.支持Dtata、JsonString、字典和数组相互转换;

4.支持字典或数组(内部可包含字典或模型)、 JsonString、 JsonData转换为模型对象(如果是JsonStringArray或者JsonData对象这直接返回模型数组);

5.WQK_Model_Protocol协议 ,支持指定数组中需要转换的类型,属性和字典KEY值匹配转换;

NSData *data = [NSJSONSerialization dataWithJSONObject:@{@"key1" : @"value1" ,
                                                       @"key2" : @"value2"}
options:NSJSONWritingPrettyPrinted error:nil];

WQKSubModel *subModel1 = [WQKSubModel new];
[subModel1 setSubName:@"小李"];
[subModel1 setSubNickName:@"xiaoxiaoLi"];
[subModel1 setSuperName:@"super李"];
[subModel1 setSuperNickName:@"superxiaoxiaoLi"];
WQKSubModel *subModel2 = [WQKSubModel new];
[subModel2 setSubName:@"小王"];
[subModel2 setSubNickName:@"xiaoxiaoWang"];
[subModel2 setSuperNickName:@"superxiaoxiaoWang"];

NSDictionary *dic1 = @{@"name" : @"小李",
                       @"nickName" : @"Li",
                       @"IDNumber" : @"3297434",
                       @"selfModel" : @{@"subName" : @"小小Li",
                                        @"subNickName" : @"xiaoLi"},
                       @"age" : @(22),
                       @"height" : @(178.32),
                       @"gender" : @(1),
                       @"dataValue" : data,
                       @"dateValue" : [NSDate date],
                       @"selfFrame" : NSStringFromCGRect(CGRectMake(123, 465, 648, 2)),
                       @"arrayValue" : @[subModel1, subModel2],
                       @"dicValue" : @{ @"subName" : @"WangName",
                                        @"subNickName" : @"MingNickName",
                                        @"subModel" : subModel1
                                        },
                       @"selfFrame" : NSStringFromCGRect(CGRectMake(123, 465, 648, 2)),
                       @"numberSize" : @(1732)
                       };
//字典转模型

// WQKRunTimeModel model1 = [WQKRunTimeModel wqk_ObjectWithDic:dic1];
WQKRunTimeModel
model1 = [[WQKRunTimeModel new] wqk_ObjectWithDic:dic1];

WQKSubModel *subModel3 = [WQKSubModel new];
[subModel3 setSubName:@"小楚"];
[subModel3 setSubNickName:@"xiaoxiaoChu"];
[subModel3 setSuperBaseID:@(1034530)];

NSDictionary *dicValue = @{ @"subName" : @"WangName",
                            @"subNickName" : @"MingNickName",
                            @"subModel" : subModel1
                            };

NSDictionary *dic2 = @{@"name" : @"小李",
                       @"nickName" : @"Li",
                       @"id" : @"3297434",
                       @"selfModel" : @{@"subName" : @"小小Li",
                                        @"subNickName" : @"xiaoLi",
                                        @"superNickName" : @"superxiaoLi"},
                       @"age" : @(22),
                       @"height" : @(178.32),
                       @"gender" : @(1),
                       @"dataValue" : [subModel3 wqk_JsonData],
                       @"dateValue" : [NSDate date],
                       @"selfFrame" : NSStringFromCGRect(CGRectMake(123, 465, 648, 2)),
                       @"arrayValue" : @[dicValue, subModel2, subModel3],
                       @"dicValue" : dicValue,
                       @"numberSize" : @(1732.33)
                       };
WQKRunTimeModel *model2 = [WQKRunTimeModel wqk_ObjectWithDic:dic2];

NSData *jsonData = [model1 wqk_JsonData];
NSString *jsonString = [model1 wqk_JsonString];
id jsonObject = [dic1 wqk_JsonObject];

id object = [[jsonData wqk_JsonString] wqk_JsonObject];

id jsonArrayObject = [@[model1, model2, model1] wqk_JsonObject];
id jsonArrayString = [@[model2, dic1, model1] wqk_JsonString];
id jsonArrayData = [@[model2, dic1, model1] wqk_JsonData];

NSArray <WQKRunTimeModel *> *modelArray = [WQKRunTimeModel wqk_ObjectWithDic:jsonArrayObject];
modelArray = [WQKRunTimeModel wqk_ObjectWithDic:jsonArrayString];
modelArray = [WQKRunTimeModel wqk_ObjectWithDic:jsonArrayData];
modelArray = [WQKRunTimeModel wqk_ObjectWithDic:@[model2, dic1, model1]];

Latest podspec

{
    "name": "WQK_Model",
    "version": "0.0.1",
    "summary": "A sunmary of WQK_Model, transform Dic to model OR models",
    "description": "the description of WQK_Model, read below, you will understand how to use WQK_Model",
    "homepage": "https://github.com/AlexCorleone/WQK_Model",
    "license": {
        "type": "Apache License, Version 2.0",
        "text": "    Licensed under the Apache License, Version 2.0 (the "License");n    you may not use this file except in compliance with the License.n    You may obtain a copy of the License atn    http://www.apache.org/licenses/LICENSE-2.0n    Unless required by applicable law or agreed to in writing, softwaren    distributed under the License is distributed on an "AS IS" BASIS,n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.n    See the License for the specific language governing permissions andn    limitations under the License.n"
    },
    "authors": {
        "AlexCorleone": "[email protected]"
    },
    "platforms": {
        "ios": null
    },
    "source": {
        "git": "https://github.com/AlexCorleone/WQK_Model.git",
        "tag": "0.0.1"
    },
    "source_files": "WQK_Model/WQK_Model/*",
    "requires_arc": true
}

Pin It on Pinterest

Share This