首页 > 技术文章 > OC基础8

Wolfanature 2016-04-15 17:07 原文

OC基础8

 

 【构造方法】
#  Person *p = [Person new];
#  new其实是+alloc与-init的结合:
#    (1)+alloc类方法进行分配空间
#    (2)-init对象方法进行初始化
#  Person *p1 = [Person alloc];
#  Person *p2 = [p1 init];




#  重写init方法
#  Person *p4 = [[Person alloc] init];

#- (id) init
#{
#    self = [super init];
#    if (self != 0)
#    {
#        _no = 1;
#    }
#    return self
#}


#
#- (id) init
#{
#    if (self = [super init]) #经典的写法
#    {
#        _no = 1;
#    }
#    return self
#}
#
#



#    自定义init方法
#   - (id)initWithAge:(int)age;




#    Xcode功能使用技巧
#   修改Xcode模板更改

推荐阅读