Global functions and capturing values in swift

2019-08-13 18:01发布

Swift documentation says that closures and nested functions can capture values while global functions can not. Why then this is not a compilation error (in fact it looks like the global funciton myFunc() captures the value.)

var myInt = 0

func myFunc()
{
    myInt+=1
}

print(myInt) //prints 0
myFunc()
print(myInt) //prints 1

I am running this in Xcode playground, could that have something to do with it?

Thanks

0条回答
登录 后发表回答