标签:
1.用模型取代字典的好处
?使用字典的坏处
dict[@"name"] =@"Jack";
NSString*name = dict[@"name"];
app.name = @"Jack”;
NSString*name = app.name;
2.字典转模型
4.字典转模型的过程
5.Sample
#import<Foundation/Foundation.h> @interface MJApp :NSObject -(NSString*)GetName; -(NSString*)GetIcon; -(instancetype) initWithDict:(NSDictionary *) dict; +(instancetype) appWithDict:(NSDictionary *) dict; @end #import "MJApp.h" @interface MJApp() @property (nonatomic,copy) NSString *name; @property (nonatomic,copy) NSString *icon; @end @implementation MJApp -(NSString*)GetName { return self.name; } -(NSString*)GetIcon { return self.icon; } -(instancetype) initWithDict:(NSDictionary *)dict { if (self = [super init]) { self.name = dict[@"name"]; self.icon = dict[@"icon"]; } return self; } +(instancetype)appWithDict:(NSDictionary *)dict { return [[self alloc] initWithDict:dict]; } @end
标签:
原文地址:http://blog.csdn.net/neng18/article/details/42193959