-
-
Save Thorsson/2cc454cdaa16cf18bcb6 to your computer and use it in GitHub Desktop.
Static variable inside of a function in Swift.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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