Calling awakeFromNib of superclass

后端 未结 2 1493
花落未央
花落未央 2020-12-30 23:56

I installed Xcode 8.0 beta (8S128d). Now I have some warnings with message:

Method possibly missing a [super awakeFromNib] call

in all

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 00:00

    As per Apple:

    You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require. Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations. You may call the super implementation at any point during your own awakeFromNib method.

    Before Xcode 8, there was no strict compiler requirement for this , howeever Apple has changed this with Xcode8, and compiler treats it as error if call to [super awakeFromNib] (or super.awakeFromNib() in swift) is missing in awakeFromNib.

    So Swift version would look something like this:

    func awakeFromNib() {
       super.awakeFromNib()
    
       ... your magical code ...
    }
    

提交回复
热议问题