[swift-users] Needing self when one initialiser method calls another.
diego at heyboyo.com
Sat Jan 16 23:32:16 CST 2016
The existence of `super` in classes makes sense as to why it's required.
On 17 January 2016 at 11:23, Brent Royal-Gordon <brent at architechies.com>
> > I'm just curious as to why the self (in bold) is needed in the init()
> that's calling init(x: Double, y: Double)? Can't the compiler infer from
> the parameters what should be called?
> My interpretation: The `self` must be explicit here to differentiate it
> from `super.init`. You can't use `super.init` in a struct, of course, but
> in a class this is a super, super crucial distinction, so it's helpful for
> the compiler to force you to be clear about this in a class. Structs have
> the same rule simply because it would be more frustrating if it were
> Brent Royal-Gordon
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users