Last active
August 29, 2018 18:26
-
-
Save nbw/c3dd4ecc3bb92666e821c3199db35e87 to your computer and use it in GitHub Desktop.
Using an OptionSet with a Dictionary
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
let DictionaryLookUp : [OptionSetHash: Bool] = [ | |
.first: true, | |
.second: false, | |
.third: true | |
] | |
// Example: cycling through options in a dictionary | |
var options = OptionSetHash.init(rawValue: 0) | |
for (key, value) in DictionaryLookUp { | |
if(value) { | |
options.update(with: key) | |
} | |
} | |
// Example: Only remember the first truthy look up | |
// | |
// Say you only wanted to unlock one achievement at a time | |
// | |
var options = OptionSetHash.init(rawValue: 1) | |
for (key, value) in DictionaryLookUp { | |
if(value && !options.contains(key)) { | |
options.update(with: key) | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment