Ulrik. S Ulrik. S - 3 months ago 8
Swift Question

How to check a value is inside nested dictionary swift

I have a problem concerning my nested dictionary.

var level1Dictionary = [String : [String : String]]()
var ChosenDeckLabel = [String]
textview.text


I want to see if the dictionary contains a certain value within my,
else if
statement as such:

else if level1Dictionary[ChosenDeckLabel[textview.text]] != nil {


this returns error:


Cannot subscript value of type String with an index of type String!


How should I cast it to check if the nested dictionary contains the value?

Answer

I think this is what you intend to do:

else if level1Dictionary[strIndex1][strIndex2] != nil {