创建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
网友评论