Why couldn't a class call any of its superclass' initializers?

[Sorry if this's been discussed before.]

As long as the superclass sub-object gets initialized, it shouldn't matter if the initializer was designated or convenience. Is there some subtle step on the two-phase initialization I'm missing? Or is this a point to extend in a future version of Swift?

···

Sent from my iPhone

I think it's some subtlety... I might vaguely remember someone saying something about it. Since a proposal didn't come of that, I'm assuming there was a technical issue or something. I could easily be wrong, though.

- Dave Sweeris

···

On Jul 25, 2017, at 9:36 PM, Daryle Walker via swift-evolution <swift-evolution@swift.org> wrote:

[Sorry if this's been discussed before.]

As long as the superclass sub-object gets initialized, it shouldn't matter if the initializer was designated or convenience. Is there some subtle step on the two-phase initialization I'm missing? Or is this a point to extend in a future version of Swift?

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

It prevents accidental infinite loops of inits, which is possible in Obj-C.

···

On Jul 26, 2017, at 12:36 AM, Daryle Walker via swift-evolution <swift-evolution@swift.org> wrote:

[Sorry if this's been discussed before.]

As long as the superclass sub-object gets initialized, it shouldn't matter if the initializer was designated or convenience. Is there some subtle step on the two-phase initialization I'm missing? Or is this a point to extend in a future version of Swift?

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Convenience initializers are complete-object initializers. A sub-object initializer from a subclass cannot delegate to a complete-object initializer from its superclass because that would re-initialize all the subclass sub-objects.

John.

···

On Jul 26, 2017, at 12:36 AM, Daryle Walker via swift-evolution <swift-evolution@swift.org> wrote:
[Sorry if this's been discussed before.]

As long as the superclass sub-object gets initialized, it shouldn't matter if the initializer was designated or convenience. Is there some subtle step on the two-phase initialization I'm missing? Or is this a point to extend in a future version of Swift?

Terms of Service

Privacy Policy

Cookie Policy