【问题标题】:How to call designated superclass initializers in Swift如何在 Swift 中调用指定的超类初始值设定项
【发布时间】:2014-06-03 09:33:21
【问题描述】:

在 Objective-C 中,初始化器中有这种标准模式来调用超类的指定初始化器。

例如:

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

在 Swift 类中进行相同初始化的标准方法是什么?

【问题讨论】:

    标签: objective-c uiview swift


    【解决方案1】:

    像这样

    init(frame: CGRect) {
        super.init(frame: frame)
        // Initialization code
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      相关资源
      最近更新 更多