Does a swift subclass *always* have to call super.init()

前端 未结 4 961
暖寄归人
暖寄归人 2021-01-30 21:46

If I have a swift subclass that:

  1. doesn\'t need to access self
  2. doesn\'t need to access any properties on self

Do

4条回答
  •  伪装坚强ぢ
    2021-01-30 22:10

    I think you don't have to call super. I tried to simulate situation as follow:

    class Animal {
    }
    
    class Parrot: Animal {
    
        override init() {
            // Some code (super not called)
        }
    }
    

    However, i would recommend to always call super.init in real app, like you use to do in Objective-C.

提交回复
热议问题