月度归档:2017年07月

iOS 第三方库 Mantle

 

Mantle 主要是简化ios中model层的第三方库,我们在项目中大量的定义和使用model,而Mantle所做的就是让我们更方便的使用model。 Mantle 目前也是我们通讯框架中最要的组成部分

直接上代码吧

HVProjectInfoModel.h

#import <Mantle/Mantle.h>
@class HVVenueWeekTimesModel;

@interface HVProjectInfoModel : MTLModel <MTLJSONSerializing>

// projectid 项目id
  //(String)
@property(nonatomic, strong) NSString* projectid;

// 项目名称
  //(String)
@property(nonatomic, strong) NSString* projectName;

//  //(List)
@property(nonatomic, strong) NSArray<HVVenueWeekTimesModel*>* scene;


+ (HVProjectInfoModel*) modelFromDictionary:(NSDictionary*)dict;

+ (NSArray<HVProjectInfoModel*>*) modelsFromArray:(NSArray<NSDictionary*>*)array;

- (NSDictionary*) dictionary;

@end

MTLJSONSerializing协议包含了一下内容

@protocol MTLJSONSerializing 
@required
+ (NSDictionary *)JSONKeyPathsByPropertyKey;
@optional
+ (NSValueTransformer *)JSONTransformerForKey:(NSString *)key;
+ (Class)classForParsingJSONDictionary:(NSDictionary *)JSONDictionary;
@end

继续阅读