MJExtension能做什么?

  1. MJExtension是一套字典和模型之间互相转换的超轻量级框架
  2. MJExtension能完成的功能

     字典(JSON) --> 模型(Model)
    模型(Model) --> 字典(JSON)
    字典数组(JSON Array) --> 模型数组(Model Array)
    模型数组(Model Array) --> 字典数组(JSON Array)

MJExtension和JSONModel、Mantle等框架的区别

1. 转换速率:

最近一次测试表明:MJExtension > JSONModel > Mantle

各位开发者也可以自行测试

2.具体用法:

JSONModel

要求所有模型类必须继承自JSONModel基类

Mantle

要求所有模型类必须继承自MTModel基类

MJExtension

不需要你的模型类继承任何特殊基类,毫无污染,毫无侵入性

如何使用MJExtension

方法一:cocoapods导入pod 'MJExtension'

方法二:手动导入

将MJExtensionExample/MJExtensionExample/MJExtension文件夹中的所有源代码拽入项目中
导入主头文件:#import "MJExtension.h"
MJExtension.h
MJConst.h
MJConst.m
MJFoundation.h
MJFoundation.m
MJIvar.h
MJIvar.m
MJType.h
MJType.m
NSObject+MJCoding.h
NSObject+MJCoding.m
NSObject+MJIvar.h
NSObject+MJIvar.m
NSObject+MJKeyValue.h
NSObject+MJKeyValue.m

最简单的字典转模型: objectWithKeyValues:

模型中嵌套模型

.模型中有个数组属性,数组里面又要装着其它模型:在模型内部实现+ (NSDictionary *)objectClassInArray方法

模型中的属性名和字典中的key不相同(或者需要多级映射)

将一个字典数组转成模型数组:objectArrayWithKeyValuesArray:

将一个模型转成字典:

// 新建模型
User *user = [[User alloc] init];
user.name = @"Jack";
user.icon = @"lufy.png"; Status *status = [[Status alloc] init];
status.user = user;
status.text = @"今天的心情不错!"; // 将模型转为字典
NSDictionary *statusDict = status.keyValues;

将一个模型数组转成字典数组:

// 新建模型数组
User *user1 = [[User alloc] init];
user1.name = @"Jack";
user1.icon = @"lufy.png"; User *user2 = [[User alloc] init];
user2.name = @"Rose";
user2.icon = @"nami.png"; NSArray *userArray = @[user1, user2];
// 将模型数组转为字典数组
NSArray *dictArray = [User keyValuesArrayWithObjectArray:userArray];
NSLog(@"%@", dictArray);
/*(
{ icon = "lufy.png"; name = Jack; },
{ icon = "nami.png"; name = Rose; } )*/

核心代码7:

[User keyValuesArrayWithObjectArray:userArray]
 链接地址:https://github.com/CoderMJLee/MJExtension

MJExtension的使用:https://github.com/CoderMJLee/MJExtension的更多相关文章

  1. 转载请注明出处: https://github.com/qiu-deqing/FE-interview

    转载请注明出处: https://github.com/qiu-deqing/FE-interview Table of Contents generated with DocToc FE-inter ...

  2. https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/

        https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ ...

  3. fatal: could not read Username for 'https://github.com': No such file or directo

    Git push origin master报错 fatal: could not read Username for 'https://github.com': No such file or di ...

  4. 结合个人经历总结的前端入门方法 (转自https://github.com/qiu-deqing/FE-learning)

    结合个人经历总结的前端入门方法 (https://github.com/qiu-deqing/FE-learning),里面有很详细的介绍. 之前一直想学习前端的,都不知道怎么下手都一年了啥也没学到, ...

  5. (2016 年) githup 博客地址 : https://github.com/JMWY/MyBlog

    githup 博客地址 : https://github.com/JMWY/MyBlog

  6. MBProgressHUD框架的使用:https://github.com/jdg/MBProgressHUD

    MBProgressHUD是一个开源类库,实现了各种样式的提示框, 下载地址:https://github.com/jdg/MBProgressHUD,然后把两个MBProgressHUD.h和MBP ...

  7. https://github.com/akullpp/awesome-java

    java stack https://github.com/akullpp/awesome-java

  8. https://github.com/oneuijs/You-Dont-Need-jQuery

    https://github.com/oneuijs/You-Dont-Need-jQuery

  9. wget https://github.com/xxx/yyy/archive/${commit_hash}.zip

    wget https://github.com/xxx/yyy/archive/${commit_hash}.zip

随机推荐

  1. Effective Java 47 Know and use the libraries

    Advantages of use the libraries By using a standard library, you take advantage of the knowledge of ...

  2. 删除CListCtrl中具有某一相同数据的所有行

    删除CListCtrl中具有某一相同数据的所有行 ================================== 本文原创,转载请注明出处:http://blog.csdn.net/wlsgzl ...

  3. 读书笔记——Windows核心编程(2)比较字符串

    1. CompareString 以符合用户语言习惯的方式,EX版本使用UNICODE int CompareString( __in LCID Locale, __in DWORD dwCmpFla ...

  4. PHP中IP地址与整型数字互相转换详解

    这篇文章主要介绍了PHP中IP地址与整型数字互相转换详解,本文介绍了使用PHP函数ip2long与long2ip的使用,以及它们的BUG介绍,最后给出自己写的两个算法,需要的朋友可以参考下 IP转换成 ...

  5. loadrunner常用函数

    1.关联函数:web_reg_save_param("session", "LB=value=", "RB=>", LAST);

  6. 对于这个函数const int func(const int& a) const声明中,三个const分别是什么意思?

    第一个const 函数的返回值类型是const. 这个const修饰没什么意义,你可以想象一下: 既然是函数的 返回值,而且是值传递的形式,是否const有什么意义.如果指针(引用)传递,怎表示返回值 ...

  7. poj 1144 Network 图的割顶判断模板

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8797   Accepted: 4116 Descripti ...

  8. Linux root 密码重置与用户管理

    ---forget root password restart your linux system press 'e' when start. press 'e' again then choose ...

  9. iOS开发之——制作framework静态库教程

    环境: 硬件:macbook air 系统:OSX EI Capitan 版本:10.11.3 xcode : Version 7.2.1 (7C1002) 最近在做ios的静态库(据说framewo ...

  10. uGUI练习(六) ScrollView

    练习目标 练习uGUI的滑动组件 一.相关组件 ScrollRect Mask Grid Layout Group Scrollbar 二.步骤 1.创建一个Panel,命名为ScrollRect,添 ...