iOS开发-初始化和便利构造器写法

初始化

- (id)initWithName:(NSString *)name
            gender:(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;
              }
    原文作者:Baaaan
    原文地址: https://segmentfault.com/a/1190000003915752
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞