初始化方法都是等同:
1.
[NSString stringWithFormat:<#(NSString *), ...#>];
[[NSString alloc]initWithFormat:<#(NSString *), ...#>:<#(NSString *)#>]
2.
[NSArray arrayWithObject:<#(id)#>];
[[NSArray alloc]initWithArray:<#(NSArray *)#>]
3.模型中设计初始化方法:
.h文件中:
3个属性:
@property (nonatomic,copy) NSString *icon;
@property (nonatomic,copy) NSString *desc;
@property (nonatomic,copy) NSString *name;
2个方法+中包含-:
-(id) initWithDict:(NSDictionary *)dict;
+(id) shopWithDict:(NSDictionary *)dict;
.m文件中:
-(id) initWithDict:(NSDictionary *)dict{
if (self = [super init]) {
self.icon = dict[@"icon"];
self.name = dict[@"name"];
self.desc = dict[@"desc"];
}
return self;
}
+(id) shopWithDict:(NSDictionary *)dict{
// Shop *s = [[Shop alloc]init];
// s.icon = dict[@"icon"];
// s.name = dict[@"name"];
// s.desc = dict[@"desc"];
return [[self alloc]initWithDict:dict];