Comparing dictionary values swift

Viewed 2398

I have an array of dictionaries of type

[["OptionId": 824, "QuestionId": 208],
["OptionId": 810, "QuestionId": 205],
["OptionId": 1017, "QuestionId": 257],
["OptionId": 0, "QuestionId": 201],
["OptionId": 0, "QuestionId": 199],
["OptionId": 0, "QuestionId": 200]]

I have iterated through these values and extracted the dictionaries values as

["OptionId": 824, "QuestionId": 208]
["OptionId": 810, "QuestionId": 205]
["OptionId": 1017, "QuestionId": 257]
["OptionId": 0, "QuestionId": 201]
["OptionId": 0, "QuestionId": 199]
["OptionId": 0, "QuestionId": 200]

Now, I want to get the "QuestionId" for all those "OptionId" which are 0. How can I compare the dictionary key-value to zero? Thanks in advance.

This is what I have tried so far:

for dictionary in arrayofDict {
    print(dictionary)
    if (dictionary["OptionId"] == 0) {
        print("option not selected")
    }
} 
4 Answers
Related