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. Windows Server 2012 R2下通过80端口访问Odoo ERP

    背景 Odoo 9.0系统,安装于Windows Server 2012R2,同时与IIS并存.Odoo自带web服务器,使用端口8069.因客户需要用80端口访问,因此需要进一步设置,且8069端口 ...

  2. JPA一对多关联

    关于JPA一对多关联这里使用Order与OrderItem来模拟.一个Order可以关联多个OrderItem,而一个OrderItem只能关联一个Order.Order与OrderItem是一对多的 ...

  3. 解决ubuntu sudo not found command的问题

    将/etc/sudoers 中Defaults env_reset改成Defaults !env_reset取消掉对PATH变量的重置, 然后在/etc/bash.bashrc中最后添加alias s ...

  4. Icacls 在windows目录文件授权中的应用

    前言 最近因工作需要,需要对批量服务器某一目录下的文件进行统一授权,对于linux来说,授权很方便,对于window来说,要对目录下的文件进行批量授权还是很不方便的,windows平台授权自然想到用i ...

  5. 快速理解Kafka分布式消息队列框架

    作者:刘旭晖 Raymond 转载请注明出处 Email:colorant at 163.com BLOG:http://blog.csdn.net/colorant/ ==是什么 == 简单的说,K ...

  6. Linux下的C之2048

    #include <stdio.h> #include <stdlib.h> #include <curses.h> #include <time.h> ...

  7. 边工作边刷题:70天一遍leetcode: day 85-2

    Paint Fence 要点: 这题是求number of ways,如果是相邻不相同颜色,那么就trivial了:k*(k-1)^(n-1).所以这里no more than two adjacen ...

  8. 漫谈计算摄像学 (一):直观理解光场(Light Field)

    什么是计算摄像学 计算摄像学(Computational Photography)是近年来越来越受到注意的一个新的领域,在学术界早已火热.本来计算摄像学的业界应用在群众中一直没什么知名度,直到Lytr ...

  9. 八皇后,回溯与递归(Python实现)

    八皇后问题是十九世纪著名的数学家高斯1850年提出 .以下为python语句的八皇后代码,摘自<Python基础教程>,代码相对于其他语言,来得短小且一次性可以打印出92种结果.同时可以扩 ...

  10. 给vs2010安装上cocos2d-x的模版

    开发环境:OS(WINDOWS 8.1 X64 企业版) cocos2d-x 2.2.1  vs2010 想给vs安装上cocos的模版,执行InstallWizardForVS2010.js,老是提 ...