I have a class sort of like the one below. It is simplified, but it illustrates my problem. I want to initialize the "number" variable with the function "square".
class SomeClass {
let number: Int
func square (num: Int) -> Int {
return num * num
}
init(num: Int) {
number = square(num)
}
}
But when i make an instance of the class. For example
let instance = SomeClass(num: 2)
it throws the error: use of 'self' in method call 'square' before all stored properties are initialized.
How can i initialize the number by using the function?