Last active
July 28, 2016 14:57
-
-
Save bryanluby/548beba8f8062c81ed68 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. | |
} | |
} |
This looks genius. What are examples where you would use this pattern?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
any idea how to do this in Swift 3? can't seem to figure it out.