一个类簇的实现示例(来自mantle的github主页)

来源:互联网 发布:淘宝买微博小号的店铺 编辑:程序博客网 时间:2024/06/06 17:08
@interface XYMessage : MTLModel@end@interface XYTextMessage: XYMessage@property (readonly, nonatomic, copy) NSString *body;@end@interface XYPictureMessage : XYMessage@property (readonly, nonatomic, strong) NSURL *imageURL;@end@implementation XYMessage+ (Class)classForParsingJSONDictionary:(NSDictionary *)JSONDictionary {    if (JSONDictionary[@"image_url"] != nil) {        return XYPictureMessage.class;    }    if (JSONDictionary[@"body"] != nil) {        return XYTextMessage.class;    }    NSAssert(NO, @"No matching class for the JSON dictionary '%@'.", JSONDictionary);    return self;}@end
0 0
原创粉丝点击