Structures constructors (initializers) in Swift
Forums:
struct Point {
var x, y: Int
init() {
x = 0
y = 0
}
init (x: Int, y: Int) {
self.x = x
self.y = y
}
}
let p1 = Point(x: 1, y: 2)
//p1.x is 1 and p1.y is 2
let p2 = Point()
//p2.x is 0 and p2.y is 0
- Log in to post comments