I confess feeling little stupid, but after hours of trying I have to ask:
class AGE {
static func getAge() -> Int {
var age: Int
for i
You need to initilize it in the beginning:
var age: Int = 0
If for some reason your for-loop don´t execute then you can´t set your age variable when you only have declared it as var age: Int
and not initilized it.
And regarding:
I even tried to set
var age: Int = 0
at the beginning, but then the function return 0
That means that you had intilizied your age variable
to 0
and the for-loop where never executed and the return will be 0
.