iOS之MVVM模式以及提高开发效率

MVVM模式与团队合作

说到架构设计和团队协作,这个对App的开发还是比较重要的。即使作为一个专业的搬砖者,前提是你这砖搬完放在哪?不只是Code有框架,其他的东西都是有框架的,比如桥梁等等神马的~在这儿就不往外扯了。一个好的工程框架不进可以提高团队的协作效率,同时还可以减少代码的冗余度和耦合性,合理的分工与系统的架构设计是少不了的。

至于团队协作不仅仅是有SVN或者Git这些版本控制工具就行的,至于如何在iOS开发中使用SVN,请参考之前的博客(iOS开发之版本控制(SVN))。一个团队可以高效的工作,本人觉得交流是最为重要的,团队中的每个人都比较和气,而且交流上没有什么障碍(不过有的团队中总有几个合不来的人),交流在团队中最为重要。至于SVN怎么用,那都不是事儿!

好了今天就以我写的一个Demo来浅谈一下iOS开发中的架构设计和团队协作,今天的咸蛋先到这儿,切入今天的话题。

为了写今天的博客我花了点时间做了个工程,这个工程后台的接口用的新浪微博的API来进行测试的,在本文的后面也会跟上GitHub的分享链接。OK~说的高大上一些就是,仁者见仁智者见智,交流思想,共同学习。

一、小酌一下MVVM

在这呢也不赘述什么是MVC,神马又是MVVM了,在百度上谷歌一下一抓一大把,在这儿就简单的提上一嘴。下面的Demo用的就是MVVM的架构模式。

Model层是少不了的了,我们得有东西充当DTO(数据传输对象),当然,用字典也是可以的,编程么,要灵活一些。Model层是比较薄的一层,如果学过Java的小伙伴的话,对JavaBean应该不陌生吧。

ViewModel层,就是View和Model层的粘合剂,他是一个放置用户输入验证逻辑,视图显示逻辑,发起网络请求和其他各种各样的代码的极好的地方。说白了,就是把原来ViewController层的业务逻辑和页面逻辑等剥离出来放到ViewModel层。

View层,就是ViewController层,他的任务就是从ViewModel层获取数据,然后显示。

上面对MVVM就先简单的这么一说,好好的理解并应用的话,还得实战。

二、关于工程中是否使用StoryBoard的论述

从网上经常看到说不推荐使用StoryBoard或者Xib,推荐用纯代码手写。个人认为这种观点是和苹果设计StoryBoard的初衷相悖的,在我做过的项目中是以StoryBoard为主,xib为辅,然后用代码整合每个StoryBoard.

举一个用Storyboard好处的例子就OK了,给控件添加约束,如果用Storyboard完成那是分分秒的事情,而用代码的添加约束的话是何等的恶心,纯代码写的话会把大量的时间花在写UI上,而且技术含量是比较低的,这个个人认为没什么必要。在团队合作中负责UI开发的小伙伴只需没人负责一个Storyboard,各开发各的,用SVN提交时把下面的勾(如下图)去掉即可,这样用Storyboard是没有问题的。然后再用代码进行整合就OK了。如果你在你的工程中加入了新的资源文件的话,用XCode自带的SVN提交的话需要吧Project Setting文件一并提交。

三、实战MVVM(用Xcode创建的Group是虚拟的文件夹,为了便于维护,建议创建物理文件夹,然后再手动引入)

1.下面通过一个实例来体会一下MVVM架构模式,下面是该工程的一级目录如下,每层之间的交互是用Block的形式来实现的

工程目录说明:

Request:文件夹下存储网络请求的类,下面会给出具体的实现

Config:就是工程的配置文件

Resource:就是工程的资源文件,下面有图片资源和Storyboard文件资源

Tools是:工具文件类,存放工具类,比如数据正则匹配等。

Vender:存放第三方类库

Model:这个就不多说了

ViewController:存放ViewController类资源文件,也就是View层

ViewModel:存放各种业务逻辑和网络请求

2.详解Request:Request负责网络请求的东西,具体如下:

NetRequestClass是存放网络请求的代码,本工程用的AF,因为本工程只是一个Demo,所以就只封装了监测网络状态,GET请求,POST请求方法,根据现实需要,还可以封装上传下载等类方法。

NetRequestClass.h中的代码如下:

//  NetRequestClass.h

//  MVVMTest

//

//  Created by 李泽鲁 on 15/1/6.

//  Copyright (c) 2015年 李泽鲁. All rights reserved.

//

#import @interface NetRequestClass : NSObject

#pragma 监测网络的可链接性

+ (BOOL) netWorkReachabilityWithURLString:(NSString *) strUrl;

#pragma POST请求

+ (void) NetRequestPOSTWithRequestURL: (NSString *) requestURLString

WithParameter: (NSDictionary *) parameter

WithReturnValeuBlock: (ReturnValueBlock) block

WithErrorCodeBlock: (ErrorCodeBlock) errorBlock

WithFailureBlock: (FailureBlock) failureBlock;

#pragma GET请求

+ (void) NetRequestGETWithRequestURL: (NSString *) requestURLString

WithParameter: (NSDictionary *) parameter

WithReturnValeuBlock: (ReturnValueBlock) block

WithErrorCodeBlock: (ErrorCodeBlock) errorBlock

WithFailureBlock: (FailureBlock) failureBlock;

@end

NetRequestClass.m中的代码如下:

//  NetRequestClass.m

//  MVVMTest

//

//  Created by 李泽鲁 on 15/1/6.

//  Copyright (c) 2015年 李泽鲁. All rights reserved.

//

#import "NetRequestClass.h"

@interface NetRequestClass ()

@end

@implementation NetRequestClass

#pragma 监测网络的可链接性

+ (BOOL) netWorkReachabilityWithURLString:(NSString *) strUrl

{

__block BOOL netState = NO;

NSURL *baseURL = [NSURL URLWithString:strUrl];

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];

NSOperationQueue *operationQueue = manager.operationQueue;

[manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {

switch(status) {

caseAFNetworkReachabilityStatusReachableViaWWAN:

caseAFNetworkReachabilityStatusReachableViaWiFi:

[operationQueue setSuspended:NO];

netState = YES;

break;

caseAFNetworkReachabilityStatusNotReachable:

netState = NO;

default:

[operationQueue setSuspended:YES];

break;

}

}];

[manager.reachabilityManager startMonitoring];

returnnetState;

}

/***************************************

在这做判断如果有dic里有errorCode

调用errorBlock(dic)

没有errorCode则调用block(dic

******************************/

#pragma --mark GET请求方式

+ (void) NetRequestGETWithRequestURL: (NSString *) requestURLString

WithParameter: (NSDictionary *) parameter

WithReturnValeuBlock: (ReturnValueBlock) block

WithErrorCodeBlock: (ErrorCodeBlock) errorBlock

WithFailureBlock: (FailureBlock) failureBlock

{

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];

AFHTTPRequestOperation *op = [manager GET:requestURLString parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];

DDLog(@"%@", dic);

block(dic);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

failureBlock();

}];

op.responseSerializer = [AFHTTPResponseSerializer serializer];

[op start];

}

#pragma --mark POST请求方式

+ (void) NetRequestPOSTWithRequestURL: (NSString *) requestURLString

WithParameter: (NSDictionary *) parameter

WithReturnValeuBlock: (ReturnValueBlock) block

WithErrorCodeBlock: (ErrorCodeBlock) errorBlock

WithFailureBlock: (FailureBlock) failureBlock

{

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];

AFHTTPRequestOperation *op = [manager POST:requestURLString parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];

DDLog(@"%@", dic);

block(dic);

/***************************************

在这做判断如果有dic里有errorCode

调用errorBlock(dic)

没有errorCode则调用block(dic

******************************/

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

failureBlock();

}];

op.responseSerializer = [AFHTTPResponseSerializer serializer];

[op start];

}

@end

3.详解Config:创建pch文件,和Config.h文件

pch文件引入常用的头文件,内容如下:

//  PrefixHeader.pch

//  MVVMTest

//

//  Created by 李泽鲁 on 15/1/6.

//  Copyright (c) 2015年 李泽鲁. All rights reserved.

//

#ifndef MVVMTest_PrefixHeader_pch

#define MVVMTest_PrefixHeader_pch

#import"AFNetworking.h"

#import "UIKit+AFNetworking.h"

#import "Config.h"

#import "NetRequestClass.h"

#import "SVProgressHUD.h"

#endif

Config.h中就是各种宏定义和各种枚举类型和block类型,代码如下:

//  Config.h

//  MVVMTest

//

//  Created by 李泽鲁 on 15/1/6.

//  Copyright (c) 2015年 李泽鲁. All rights reserved.

//

#ifndef MVVMTest_Config_h

#define MVVMTest_Config_h

//定义返回请求数据的block类型

typedef void (^ReturnValueBlock) (id returnValue);

typedef void (^ErrorCodeBlock) (id errorCode);

typedef void (^FailureBlock)();

typedef void (^NetWorkBlock)(BOOL netConnetState);

#define DDLog(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

//accessToken

#define ACCESSTOKEN @"你自己的access_token"

//请求公共微博的网络接口

#define REQUESTPUBLICURL @"https://api.weibo.com/2/statuses/public_timeline.json"

#define SOURCE @"source"

#define TOKEN @"access_token"

#define COUNT @"count"

#define STATUSES @"statuses"

#define CREATETIME @"created_at"

#define WEIBOID @"id"

#define WEIBOTEXT @"text"

#define USER @"user"

#define UID @"id"

#define HEADIMAGEURL @"profile_image_url"

#define USERNAME @"screen_name"

#endif

4.详解资源文件Resource,结构如下图:

Image中就存放各种图片(3x,2x等),InterfaceBuider里面就是放一些Xib和Storyboard文件,每个负责UI的开发人员负责一个Storyboard

5.详解Model:本工程用的是请求公共微博接口我们需要在页面上现实用户的头像,用户名,发布日期,博文,已经隐式的用户ID和微博ID,文件目录结构如下:

PublicModel中的内容如下:

//  PublicModel.h

//  MVVMTest

//

//  Created by 李泽鲁 on 15/1/8.

//  Copyright (c) 2015年 李泽鲁. All rights reserved.

//

#import @interface PublicModel : NSObject

@property (strong, nonatomic) NSString *userId;

@property (strong, nonatomic) NSString *weiboId;

@property (strong, nonatomic) NSString *userName;

@property (strong, nonatomic) NSURL *imageUrl;

@property (strong, nonatomic) NSString *date;

@property (strong, nonatomic) NSString *text;

@end

6.详解ViewModel层,本层是最为重要的一层,下面是本层的详细截图,ViewModeClass是所有ViewMode的父类,其中存储着共同部分

ViewModelClass.h中的内容如下:

//  ViewModelClass.h

//  MVVMTest

//

//  Created by 李泽鲁 on 15/1/8.

//  Copyright (c) 2015年 李泽鲁. All rights reserved.

//

#import @interface ViewModelClass : NSObject

@property (strong, nonatomic) ReturnValueBlock returnBlock;

@property (strong, nonatomic) ErrorCodeBlock errorBlock;

@property (strong, nonatomic) FailureBlock failureBlock;

//获取网络的链接状态

-(void) netWorkStateWithNetConnectBlock: (NetWorkBlock) netConnectBlock WithURlStr: (NSString *) strURl;

// 传入交互的Block块

-(void) setBlockWithReturnBlock: (ReturnValueBlock) returnBlock

WithErrorBlock: (ErrorCodeBlock) errorBlock

WithFailureBlock: (FailureBlock) failureBlock;

@end

ViewModelClass.m中的内容如下:

//  ViewModelClass.m

//  MVVMTest

//

//  Created by 李泽鲁 on 15/1/8.

//  Copyright (c) 2015年 李泽鲁. All rights reserved.

//

#import "ViewModelClass.h"

@implementation ViewModelClass

#pragma 获取网络可到达状态

-(void) netWorkStateWithNetConnectBlock: (NetWorkBlock) netConnectBlock WithURlStr: (NSString *) strURl;

{

BOOL netState = [NetRequestClass netWorkReachabilityWithURLString:strURl];

netConnectBlock(netState);

}

#pragma 接收穿过来的block

-(void) setBlockWithReturnBlock: (ReturnValueBlock) returnBlock

WithErrorBlock: (ErrorCodeBlock) errorBlock

WithFailureBlock: (FailureBlock) failureBlock

{

_returnBlock = returnBlock;

_errorBlock = errorBlock;

_failureBlock = failureBlock;

}

@end

PublicWeiboViewModel.h中的内容如下:

//  PublicWeiboViewModel.h

//  MVVMTest

//

//  Created by 李泽鲁 on 15/1/8.

//  Copyright (c) 2015年 李泽鲁. All rights reserved.

//

#import "ViewModelClass.h"

#import "PublicModel.h"

@interface PublicWeiboViewModel : ViewModelClass

//获取围脖列表

-(void) fetchPublicWeiBo;

//跳转到微博详情页

-(void) weiboDetailWithPublicModel: (PublicModel *) publicModel WithViewController: (UIViewController *)superController;

@end

PublicWeiboViewModel.m中的内容如下:

//  PublicWeiboViewModel.m

//  MVVMTest

//

//  Created by 李泽鲁 on 15/1/8.

//  Copyright (c) 2015年 李泽鲁. All rights reserved.

//

#import "PublicWeiboViewModel.h"

#import "PublicDetailViewController.h"

@implementation PublicWeiboViewModel

//获取公共微博

-(void) fetchPublicWeiBo

{

NSDictionary *parameter = @{TOKEN: ACCESSTOKEN,

COUNT: @"100"

};

[NetRequestClass NetRequestGETWithRequestURL:REQUESTPUBLICURL WithParameter:parameter WithReturnValeuBlock:^(id returnValue) {

DDLog(@"%@", returnValue);

[self fetchValueSuccessWithDic:returnValue];

} WithErrorCodeBlock:^(id errorCode) {

DDLog(@"%@", errorCode);

[self errorCodeWithDic:errorCode];

} WithFailureBlock:^{

[self netFailure];

DDLog(@"网络异常");

}];

}

#pragma 获取到正确的数据,对正确的数据进行处理

-(void)fetchValueSuccessWithDic: (NSDictionary *) returnValue

{

//对从后台获取的数据进行处理,然后传给ViewController层进行显示

NSArray *statuses = returnValue[STATUSES];

NSMutableArray *publicModelArray = [[NSMutableArray alloc] initWithCapacity:statuses.count];

for(int i = 0; i < statuses.count; i ++) {

PublicModel *publicModel = [[PublicModel alloc] init];

//设置时间

NSDateFormatter *iosDateFormater=[[NSDateFormatter alloc]init];

iosDateFormater.dateFormat=@"EEE MMM d HH:mm:ss Z yyyy";

//必须设置,否则无法解析

iosDateFormater.locale=[[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];

NSDate *date=[iosDateFormater dateFromString:statuses[i][CREATETIME]];

//目的格式

NSDateFormatter *resultFormatter=[[NSDateFormatter alloc]init];

[resultFormatter setDateFormat:@"MM月dd日 HH:mm"];

publicModel.date = [resultFormatter stringFromDate:date];

publicModel.userName = statuses[i][USER][USERNAME];

publicModel.text = statuses[i][WEIBOTEXT];

publicModel.imageUrl = [NSURL URLWithString:statuses[i][USER][HEADIMAGEURL]];

publicModel.userId = statuses[i][USER][UID];

publicModel.weiboId = statuses[i][WEIBOID];

[publicModelArray addObject:publicModel];

}

self.returnBlock(publicModelArray);

}

#pragma 对ErrorCode进行处理

-(void) errorCodeWithDic: (NSDictionary *) errorDic

{

self.errorBlock(errorDic);

}

#pragma 对网路异常进行处理

-(void) netFailure

{

self.failureBlock();

}

#pragma 跳转到详情页面,如需网路请求的,可在此方法中添加相应的网络请求

-(void) weiboDetailWithPublicModel: (PublicModel *) publicModel WithViewController:(UIViewController *)superController

{

DDLog(@"%@,%@,%@",publicModel.userId,publicModel.weiboId,publicModel.text);

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"bundle:[NSBundle mainBundle]];

PublicDetailViewController *detailController = [storyboard instantiateViewControllerWithIdentifier:@"PublicDetailViewController"];

detailController.publicModel = publicModel;

[superController.navigationController pushViewController:detailController animated:YES];

}

@end

7.ViewController层的目录结构如下:

上面的代码就不一一粘了(主要是手按command + C 按累了),后面的链接会有源码

8.storybord中的结构如下:

运行的最终效果:

9.完整目录结构,页面间的业务逻辑,和网络的请求数据是放在ViewModel层的,当然了这也不是绝对的,要灵活把握。我个人是特别喜欢编程的,因为编程灵活起来就会很有乐趣。

10.文章快结束了,在这儿在总结一下SVN使用频率比较高的而且比较重要的命令吧(当然,本人平时主要是用XCode自带的SVN可视化管理~)

(1)、更新本地代码命令

svn  up 更新版本

svn info 查看当前版本信息

(2)、代码的提交

svn info 查看当前本地版本信息

svn up 更新到最新版本信息

svn st 查看文件状态 M-修改  D-删除 A-添加 U-更新  ?-未知状态  !-警告  C-冲突

svn add fileName: 如果出现?一般是添加文件时出的问题,在把文件svn add fileName一下后,该文件的状态会改成A

svn del fileName:如果出现!一般是删除文件时会出现的警告需呀执行svn del fileName命令后,该文件的状态会改成D

svn ci -m"提交的原因"

在文章的最后呢附上DEMO的GitHub下载地址:https://github.com/lizelu/MVVM

以上是参考优秀博客:

http://www.cocoachina.com/ios/20150122/10987.html

他把所有的数据处理逻辑都放在了继承VM的类里,现在我想把他代码优化一下,根据需求一般后台会返回一个msgCode,我在VM基类做一个数据的预处理,这样会比较方便而且条理清晰明朗:

VM子类解析json
如何提高开发效率(JSONModel以及自动生成Model属性插件)

JSONModel的使用

Adding JSONModel to your project (https://github.com/icanzilb/JSONModel)

添加JSONModel到你的项目中

Requirements

需要的环境

ARC only; iOS 5.0+ / OSX 10.7+

SystemConfiguration.framework(需要导入系统库)

Get it as: 1) source files

Download the JSONModel repository as azip fileor clone it

下载JSONModel.zip文件

Copy the JSONModel sub-folder into your Xcode project

将它拷贝到你的项目中

Link your app to SystemConfiguration.framework

导入SystemConfiguration.framework框架

or 2) via Cocoa pods

使用Cocoa pods引入

In your project'sPodfileadd the JSONModel pod:

pod 'JSONModel'

If you want to read more about CocoaPods, have a look atthis short tutorial.

如果你想关于CocoaPods了解更多,请参考这个简单的教程

Source code documentation

源码文档

The source code includes class docs, which you can build yourself and import into Xcode:

源码包含了类的文档,你也可以自己编译并且导入到xcode

If you don't already haveappledocinstalled, install it withhomebrewby typing brew install appledoc.

如果你还没有安装appledoc,先安装appledoc

Install the documentation into Xcode by typing appledoc .

in the root directory of the repository.

在xcode上安装appledoc文档,在根目录下

Restart Xcode if it's already running.

重启xcode

Basic usage

基本使用

Consider you have a JSON like this:

假如你的JSON数据像这样:

{"id":"10", "country":"Germany", "dialCode": 49, "isInEurope":true}

Create a new Objective-C class for your data model and make it inherit the JSONModel class.

创建一个Objective-C类,继承自JSONModel

Declare properties in your header file with the name of the JSON keys:

将JSON中的keys在.h文件中声明为属性

#import"JSONModel.h"

@interface CountryModel:JSONModel

@property(assign,nonatomic)int id;

@property(strong,nonatomic)NSString* country;

@property(strong,nonatomic)NSString* dialCode;

@property(assign,nonatomic)BOOL isInEurope;

@end

There's no need to do anything in the .m file.

在.m文件中不需要做任何事情

Initialize your model with data:

用数据初始化你的model

#import"CountryModel.h"...NSString* json = (fetch here JSON from Internet) ...NSError* err =nil;CountryModel* country = [[CountryModel alloc] initWithString:json    error:&err];

If the validation of the JSON passes you have all the corresponding    properties in your model populated from the JSON. JSONModel will

also try to convert as much data to the types you expect, in the example above it will:

如果传过来的JSON合法,你所定义的所有的属性都会与该JSON的值想对应,甚至JSONModel会尝试去转换数据为你期望的类型,如上所示:

convert "id" from string (in the JSON) to an int for your class

just copy country's value

转换id,从字符串转换为int

convert dialCode from number (in the JSON) to an NSString value

转换diaCode,从number转换为字符串

finally convert isInEurope to a BOOL for your BOOL property

最后一个是将isInEurope转换为BOOL属性

And the good news is all you had to do is define the properties and their expected types.

所以,你所需要做的就是将你的属性定义为期望的类型

Online tutorials

在线教程

Official website:http://www.jsonmodel.com

Class docs online:http://jsonmodel.com/docs/

Step-by-step tutorials:

傻瓜教程:

How to fetch and parse JSON by using data models

Performance optimisation for working with JSON feeds via JSONModel

How to make a YouTube app using MGBox and JSONModel

Examples

例子

Automatic name based mapping

命名自动匹配

{

"id": "123",

"name": "Product name",

"price": 12.95

}

@interface ProductModel:JSONModel

@property(assign,nonatomic)int id;

@property(strong,nonatomic)NSString*name;

@property(assign,nonatomic)floatprice;

@end

@implementation ProductModel

@end

Model cascading (models including other models)

模型嵌套(模型包含模型)

{

"order_id":104,"total_price":13.45,"product":{"id":"123","name":"Product name","price":12.95

}

}

@interface OrderModel:JSONModel

@property(assign,nonatomic)intorder_id;

@property(assign,nonatomic)floattotal_price;

@property(strong,nonatomic) ProductModel* product;

@end

@implementation OrderModel

@end

快速生成Model属性插件:

ESJsonFormat-Xcode

将JSON格式化输出为模型的属性    个人活动范围>Weibo-EnjoySR

写在之前的注意

JSON中的key对应的value为Null的话会格式化成NSString类型

格式化之前光标放在你需要添加属性的地方

如果不输出到文件,RootClass需要自己手动创建,插件只负责RootClass里面的属性生成

生成的 MJExtension 框架中objectClassInArray方法(类方法)

怎么安装:

方式1:下载-Xcode打开-Command+B-重启Xcode

方式2:通过Alcatraz安装,搜索ESJsonFormat

方式3:下载-解压plugin文件夹中zip到~/Library/Application Support/Developer/Shared/Xcode/Plug-ins-重启Xcode

怎么使用:

Window-ESJsonFormat-输入Json-EnterOR快捷键(Control+Shift+J)-输入JSON-Enter

关于设置:

打开方式:Xcode菜单-Window-ESJsonFormat-Setting

1)是否生成的 MJExtension 框架中objectClassInArray方法(类方法,默认勾选)

2)是否格式化输出泛型(Xcode 7 及之后才有效,默认勾选)

3)是否输出到文件(如果勾选,不用自己新建 RootClass。默认不勾选)

4)key为id关键字的话是否大写(默认不勾选)

注:输出到文件的内容还需要添加什么的可以联系我,人个认为不用像 JSON Accelerator 一样生成字典转模型的方法以及@synthesize修饰符,建议使用->MJExtension,保型模型清爽干净。

功能说明:

-0.1

通过JSON字符串生成对应属性

通过文件写入的方式生成到.m文件

支持输入嵌套模型名称

-0.2

支持Swift

修复JSON的value的值为Null的时候多出来的空行

修复BOOL类型值格式化失效问题

-0.3

支持生成MJExtension框架中objectClassInArray方法

修复数组嵌套多级,里面子数组不能格式化的Bug

-0.4

支持格式输出到文件

支持格式输出泛型(Xcode 7及之后)

Alcatraz

支持Alcatraz,请搜索ESJsonFormat

JSON格式

{

"name": "王五",

"gender": "man",

"age": 15,

"height": "140cm"

}

{

"name": "王五",

"gender": "man",

"age": 15,

"height": "140cm",

"addr": {

"province": "fujian",

"city": "quanzhou",

"code": "300000"

},

"hobby": [

{

"name": "billiards",

"code": "1"

},

{

"name": "computerGame",

"code": "2"

}

]

}

参考博客:

http://www.cocoachina.com/ios/20150122/10987.html

http://www.jianshu.com/p/3cce56f374b4

https://github.com/EnjoySR/ESJsonFormat-Xcode



最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,560评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,104评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,297评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,869评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,275评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,563评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,833评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,543评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,245评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,512评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,011评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,359评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,006评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,062评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,825评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,590评论 2 273
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,501评论 2 268

推荐阅读更多精彩内容