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. c++虚函数,纯虚函数,抽象类,覆盖,重载,隐藏

    C++虚函数表解析(转) ——写的真不错,忍不住转了  http://blog.csdn.net/hairetz/article/details/4137000 浅谈C++多态性  http://bl ...

  2. MS SqlServer学习笔记(索引)

    1.索引分类 MS SqlServer提供了两种索引:聚集索引和非聚集索引: 聚集索引是将数据按照索引的顺序存放 非聚集索引是将索引和数据分离存放,通过指针将二者联系到一起. 因为两种索引对比: 使用 ...

  3. 网站的SEO

    提高网站SEO排名的策略除了要有高质量的内容,还有几种方案可以使用 1.关键词的设定 合适的关键词可以提升搜索引擎中的排名 ①最重要的是html中的title标签,这也是一个页面的最重要的概括,所以尽 ...

  4. C# PDF打印

    C#中使用iTextSharp生成并下载PDF很方便. 首先要将iTextSharp的dll下载并引入项目 主要分成两部分,一部分是PDF的Document生成,另一部分就是将Document输出到页 ...

  5. 使用Httpclient来替代客户端的jsonp跨域解决方案

    最近接手一个项目,新项目需要调用老项目的接口,但是老项目和新项目不再同一个域名下,所以必须进行跨域调用了,但是老项目又不能进行任何修改,所以jsonp也无法解决了,于是想到了使用了Httpclient ...

  6. 修复 Java 内存模型,第 1 部分——Brian Goetz

    转自Java并发大师Brain Goetz:http://www.ibm.com/developerworks/cn/java/j-jtp02244/ (中文地址) http://www.ibm.co ...

  7. C# listview 拖动节点

    /// <summary> /// 当拖动某项时触发 /// </summary> /// <param name="sender"></ ...

  8. MySQL中EXPLAIN的解释

    EXPLAIN是查看MySQL优化器如何决定执行查询的主要方法,这个功能具有局限性,以为它并总是会说出真相,但是却可以获得最好信息. 学会解释EXPLAIN,你就会了解MySQL优化器是如何工作,你才 ...

  9. 20 Web 编程 - 《Python 核心编程》

  10. Flume practices and sqoop hive 2 oracle

    #receive the file flume-ng agent --conf conf --conf-file conf1.conf --name a1 flume-ng agent --conf ...