自定义Model类

声明文件

#import <Foundation/Foundation.h>

@interface OrderRecordModel : NSObject

@property (nonatomic, copy) NSString *orderCode;
@property (nonatomic, copy) NSString *createTime;

- (instancetype)initWithDict:(NSDictionary *)dict;
+ (OrderRecordModel *)modelFromDict:(NSDictionary *)dict;
+ (NSMutableArray *)getModelArrayFromModelArray:(NSArray *)array;

@end

 

实现文件

#import "OrderRecordModel.h"
@implementation OrderRecordModel

- (instancetype)initWithDict:(NSDictionary*)dict
{
    if (self = [super init]) {
        
        self.orderCode = dict[@"OrderCode"];
        self.createTime = dict[@"CreateTime"];
        
    }
    return self;
}

+ (OrderRecordModel *)modelFromDict:(NSDictionary *)dict
{
    OrderRecordModel *model = [[OrderRecordModel alloc] initWithDict:dict];
    return model;
}

+ (NSMutableArray *)getModelArrayFromModelArray:(NSArray *)array
{
    NSMutableArray *mutableArray = [array mutableCopy];
    for (NSInteger i = 0; i<mutableArray.count; i++) {
        NSDictionary *dic = mutableArray[i];
        OrderRecordModel *model = [OrderRecordModel modelFromDict:dic];
        [mutableArray replaceObjectAtIndex:i withObject:model];
    }
    return mutableArray;
}

@end

 

posted @ 2018-04-03 23:29  码出境界  阅读(204)  评论(0编辑  收藏  举报