Mantle是Cocoa和CocoaTouch的模型框架,你可以通过它为你的Cocoa和CocoaTouch写简单的模型层。
示例代码:
@interface XYUser : MTLModel@property (readonly, nonatomic, copy) NSString *name;@property (readonly, nonatomic, strong) NSDate *createdAt;@property (readonly, nonatomic, assign, getter = isMeUser) BOOL meUser;@property (readonly, nonatomic, strong) XYHelper *helper;@end@implementation XYUser+ (NSDictionary *)JSONKeyPathsByPropertyKey { return @{ @"name": @"name", @"createdAt": @"created_at" };}- (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error { self = [super initWithDictionary:dictionaryValue error:error]; if (self == nil) return nil; _helper = [XYHelper helperWithName:self.name createdAt:self.createdAt]; return self;}@end
评论