How do I loop through a dictionary and check for each items value type?
Example dictionary:
var dict = ([
"a number" : 1,
"a boolean" : false,
"a string" : "Hello"
])
My attempts at checking for values:
for item in dict.1 {
if let current = item as? NSNumber {
print(current)
}
}
and I tried this:
for item in settings {
if item[1] == item[1] as NSNumber {
print(item)
}
}
Important note:
As @Leo pointed out, it's important to keep track of what your dictionary's value type is while comparing. The dictionary that I included as my example would be of type [String : NSObject]
and the dictionary in my project was of type [String : NSNumber]
. They have to be approached differently!