I defined a struct in a function, no matter how many times I invoked the function, struct definition seems like always be the first time function invoked.
the code:
var g = 0
func f() {
struct InnerStruct{
static var attr:Int = g
}
println("static attr value is \(InnerStruct.attr), g is \(g)")
}
f()
g++
f()
g++
f()
the result is :
static attr value is 0, g is 0
static attr value is 0, g is 1
static attr value is 0, g is 2
Program ended with exit code: 0
I am not familiar with swift, can any body explain why?