美文网首页
iOS 基于MJExtension第三方BaseModel的创建

iOS 基于MJExtension第三方BaseModel的创建

作者: 隔墙送来秋千影 | 来源:发表于2018-05-17 15:57 被阅读25次

创建Model时,所继承使用到的Model基类、

BaseModel.h

#import <Foundation/Foundation.h>

@interface BaseModel : NSObject

@end

BaseModel.m

#import "BaseModel.h"

@implementation BaseModel

- (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property {
    if (property.type.typeClass == [NSString class]) {
        if (oldValue == nil) return @"";
    } else if (property.type.typeClass == [NSDate class]) {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *date = [dateFormatter dateFromString:oldValue];
        return date;
    }
    return oldValue;
}

+(NSDictionary *)mj_replacedKeyFromPropertyName {
    // 实现这个方法的目的:告诉MJExtension框架模型中的属性名对应着字典的哪个key
    return @{@"Id" : @"id"};
}

@end

相关文章

网友评论

      本文标题:iOS 基于MJExtension第三方BaseModel的创建

      本文链接:https://www.haomeiwen.com/subject/dmgbdftx.html