Swift error using initialized properties in expressions before super.init

前端 未结 2 1003
忘了有多久
忘了有多久 2021-01-13 21:46

This isn\'t critical, and there are workarounds, but it is perplexing.

See the minimal example below. I\'m referring to an initialized property, but before callin

2条回答
  •  灰色年华
    2021-01-13 22:23

    I think it is intended behavior and part of the two phase initialization.

    This is a result of the following rules:

    • All properties must be initialized before super.init is called, that is at the same line as the declaration or in init before super.init
    • An initializer may not call any instance methods, read the values of any instance properties, or refer to self as a value until after the first phase of initialization is complete

提交回复
热议问题