I want CurrendData.location
to get its random value once CurrentData
gets initialized. I came up following code:
struct CurrentData {
var size: (x: Int, y: Int)
var location: (x: Int, y: Int)
init(size: (x: Int, y: Int)) {
self.size = size
self.location = (getRandom(size.x), getRandom(size.y)) //error
}
private func getRandom (_ value:Int) -> Int {
return Int.random(in: 0...value-1)
}
}
But I get this error: "'self' used before all stored properties are initialized". How can it be fixed?