iOS开发-初始化和便利构造器写法
初始化
- (id)initWithName:(NSString *)namegender:(NSInteger)age{ if(self = [super init]){ _name = name; _age = age; } return self;}
便利构造器
+ (id)personWithName:(NSString *)name gender:(NSInteger)age{ Person *person = [[Person alloc]initWithName:name gender:gender]; return person; }