swift2 - How to check dictionary contains certain value, not certain key? -
fast way check if dictionary contains value, "dictionary.contains(value)" in java. ex:
var dict:[int:string?] = [1:"hello", 2:"world"]
how can check if dictionary contains "world"?
your option iterate on each dictionary element find if value present. there multiple ways that, linear-time.
one such way be:
foreach (key, value) in dict { if value == "world" { print("found world") } }
another (shorter) way be:
dict.values.contains("world")
Comments
Post a Comment