Skip to content

Instantly share code, notes, and snippets.

@Thorsson
Forked from bryanluby/gist:548beba8f8062c81ed68
Created October 18, 2015 13:46
Show Gist options
  • Save Thorsson/2cc454cdaa16cf18bcb6 to your computer and use it in GitHub Desktop.
Save Thorsson/2cc454cdaa16cf18bcb6 to your computer and use it in GitHub Desktop.
Static variable inside of a function in Swift.
func staticInsideFunction() {
struct Temp { static var hasAnimated = false }
if Temp.hasAnimated == false {
// ... do something only on the first function call.
Temp.hasAnimated = true
} else {
// ... do something on all subsequent function calls.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment