Swift: 'super.init' isn't called on all paths before returning from initializer?

后端 未结 2 970
小蘑菇
小蘑菇 2021-01-18 21:06

I am getting this error on the last brace of a init in a class of mine. The class looks something like the following (I market the spot where error happens):



        
2条回答
  •  爱一瞬间的悲伤
    2021-01-18 21:57

    Here is what I found on Swift Programming Language:

    In the first phase, each stored property is assigned an initial value by the class that introduced it. Once the initial state for every stored property has been determined, the second phase begins, and each class is given the opportunity to customize its stored properties further before the new instance is considered ready for use.

    A designated initializer must ensure that all of the properties introduced by its class are initialized before it delegates up to a superclass initializer.

    Hope this can explain that question.

提交回复
热议问题