深入浅出Objective-C笔记(四)

2015-11-18  本文已影响34人  无聊的呆子

对象的初始化


解决方案

 @interface People : NSObject
  {
      double height;
      double weight;
  }
  - (void) initWithHeight : (double)h andWeight : (double)w;//新加的初始化方法
  - (void) growUpByHeight : (double)h andWeight : (double)w;
  @end 

初始化方法的实现

- (id) initWithHeight : (double)h andWeight : (double)w {
    self = [super init];
    if (self) {
        weight = w;
        height = h;
    }
    return self;
  }

  所有类的初始化方法的实现在ObjC里框架基本一致。
小结

自己在类里写带参数的初始化方法

上一篇 下一篇

猜你喜欢

热点阅读