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

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -