Created
December 11, 2017 21:24
-
-
Save efremidze/cef8b0f3570b7e490978fb7e2c0dfa4e to your computer and use it in GitHub Desktop.
This file contains 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
extension UserDefaults { | |
func set(forEvery: Int, for key: String, onChange: () -> Void) { | |
let count = integer(forKey: key) % forEvery | |
if count == 0 { onChange() } | |
set(count + 1, forKey: key) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment