Ios dictionary-to-Model
# Import
@ Interface AppInfo: NSObject @ property (nonatomic, copy) NSString * name; @ property (nonatomic, copy) NSString * icon; // instancetype (instancetype) initWithDic :( NSDictionary *) dic; // The class method can quickly instantiate a model + (instancetype) appInfoWithDic :( NSDictionary *) dic; @ end
-------. M file
# Import AppInfo. h @ implementation AppInfo // dictionary instantiation model-(instancetype) initWithDic :( NSDictionary *) dic {self = [super init]; if (self) {self. name = dic [@ name]; self. icon = dic [@ icon];} return self;} // class method instantiate a model + (instancetype) appInfoWithDic :( NSDictionary *) dic {return [[self alloc] initWithDic: dic] ;}@ end
The difference between id and instancetype ,,
Id is a universal pointer type
Instancetype can be used to check the return type during compilation.