I have a class and initialize the attributes with default values:
class Point {
var x : Int
var y : Int
public init() {
x = 1
y = 1
}
}
Now I want to have a reset() method which sets the attributes to these default values. Because I want to prevent redundancies I try to move the lines from the initializer to the reset method and call this method from init:
class Point {
var x : Int
var y : Int
public init() {
reset()
}
public func reset() {
x = 1
y = 1
}
}
But it doesn't work. It says that the attributes have to be initialized. How can I fix this issue?