I\'m trying to figure out how to declare a static variable scoped only locally to a function in Swift.
In C, this might look something like this:
int
Another solution
func makeIncrementerClosure() -> () -> Int { var timesCalled = 0 func incrementer() -> Int { timesCalled += 1 return timesCalled } return incrementer } let foo = makeIncrementerClosure() foo() // returns 1 foo() // returns 2