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

Diego Barros diego at heyboyo.com
Thu Jan 14 22:48:00 CST 2016


Hi all,

​Given the ​following example:

struct Vector {

var x: Double

var y: Double

init() {

*self.init(x: 0, y: 0)*

}

init(x: Double, y: Double) {

self.x = y

self.y = y

}

}


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?


- Diego
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160115/c1f00eae/attachment.html>


More information about the swift-users mailing list