Skip to content

Instantly share code, notes, and snippets.

@nbw
Last active August 29, 2018 18:26
Show Gist options
  • Save nbw/c3dd4ecc3bb92666e821c3199db35e87 to your computer and use it in GitHub Desktop.
Save nbw/c3dd4ecc3bb92666e821c3199db35e87 to your computer and use it in GitHub Desktop.
Using an OptionSet with a Dictionary
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