What is the equivalent of a Java HashMap in Swift

I believe you can use a dictionary. Here are two ways to do the dictionary part.

var someProtocol = [String : Int]()
someProtocol["one"] = 1
someProtocol["two"] = 2

or try this which uses type inference

var someProtocol = [
    "one" : 1,
    "two" : 2
]

as for the for loop

var index: Int
for (e, value) in someProtocol  {
    index = value
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)