Why doesn't Swift force my designated initializer to call super?

前端 未结 1 466
孤街浪徒
孤街浪徒 2021-01-14 12:31

This code is legal in Swift:

class Snapper : NSObject {
    var anim : UIDynamicAnimator
    init(referenceView:UIView) {
        self.anim = UIDynamicAnimat         


        
1条回答
  •  生来不讨喜
    2021-01-14 12:58

    It's not an answer of the why but adding a symbolic breakpoint on [NSObject init] shows that it gets called even if super.init() is commented out.

    It definitely seems a special case as replacing NSObject with any other class makes the compiler warn again about the missing super call. My guess is the the compiler handles this as a special case given that it's our base class with just one known designated initializer.

    0 讨论(0)
提交回复
热议问题