[swift-users] Needing self when one initialiser method calls another.

Diego Barros 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.

-- diego

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
> inconsistent.
> --
> Brent Royal-Gordon
> Architechies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160117/55b242c5/attachment.html>

More information about the swift-users mailing list