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. 【AdaBoost算法】强分类器训练过程

    一.强分类器训练过程 算法原理如下(参考自VIOLA P, JONES M. Robust real time object detection[A] . 8th IEEE International ...

  2. 手动将自定制的WebPart部署到 SharePoint 2010 中

    1.搭建好开发环境,建立webpart工程,写代码. 2.修改assembly.cs文件   在部署前,需要修改assembly文件,增加以下两句: using System.Security; [a ...

  3. JSON转换类(二)--List转换成Json、对象集合转换Json等

    #region List转换成Json /// <summary> /// List转换成Json /// </summary> public static string Li ...

  4. hping3

    [root@zxserver104 ~]# hping3 -c -d -S -w -p --flood --rand-source 115.236.6x.19x 1. hping3 = 应用程序二进制 ...

  5. loadrunner常用函数

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

  6. matlab2015b调用摄像头

    参考链接:http://blog.csdn.net/lyqmath/article/details/7307429 本人电脑是宏碁T5000 调用代码: % By lyqmathclc; clear ...

  7. jquery parent和parents,children和find

    parent返回匹配元素的父元素的元素集合:parents返回匹配元素的祖先元素的元素集合. children返回匹配元素的子元素的元素集合:find返回匹配元素的后代元素的元素集合.

  8. D_S 线性表的顺序表示和实现

    线性表的顺序表示又称为顺序存储结构或顺序映像 顺序存储定义:把逻辑上相邻的数据元素存储在物理上相邻的存储单元中的存储结构,简言之,逻辑上相邻,物理上也相邻 顺序存储方法:用一组地址连续的存储单元依次存 ...

  9. html的input输入框边框

    1.输入框边框完全隐藏<input type="text" style="outline:none;border:0" /> 2.input去边框立 ...

  10. six month dormancy test

    source data: accountleg    year_month    amount acc1A    2010-01    100 acc1A    2010-02    100 acc1 ...