I have dictionary :
var DictPl11 = [Int: String]()
I want to check for all integers, that are connected with one same string. For example with string "0":
DictPl11 = [1: "0", 4: "1", 3: "0", 6: "0"]
I want to print Int values 1, 3, 6
Thank you
I have dictionary :
var DictPl11 = [Int: String]()
I want to check for all integers, that are connected with one same string. For example with string "0":
DictPl11 = [1: "0", 4: "1", 3: "0", 6: "0"]
I want to print Int values 1, 3, 6
Thank you
For that you can try like this way.
var DictPl11 = [1: "0", 4: "1", 3: "0", 6: "0"]
var keyArray = DictPl11.flatMap { $1 == "0" ? $0 : nil }
// [1, 3, 6] Keep in mind that this array doesn't have any order
You can try everything in PlayGround before asking, by the way.
You probably need to explicitly declare the type of your variable DictPl11 as [Int: String], as it crashed in my PlayGround.
By fast enumerating, you can get and print the key and value of your dictionary like so:
var DictPl11 = [1: "0", 4: "1", 3: "0", 6: "0"] as [Int: String]
for (key, value) in DictPl11 {
print("key: \(key)")
print("value: \(value)")
}