Global functions and capturing values in swift

蹲街弑〆低调 提交于 2019-12-11 12:23:08

问题


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

来源:https://stackoverflow.com/questions/36716013/global-functions-and-capturing-values-in-swift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!