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

Brent Royal-Gordon brent at architechies.com
Sat Jan 16 18:23:28 CST 2016


> 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



More information about the swift-users mailing list