I have an example written in Java that I would like to convert into Swift. Below is a section of the code. I would really appreciate if you can help.
Map<String, Integer> someProtocol = new HashMap<>();
someProtocol.put("one", Integer.valueOf(1));
someProtocol.put("two", Integer.valueOf(2));
for (Map.Entry<String, Integer> e : someProtocol.entrySet() {
int index = e.getValue();
...
}
NOTE: entrySet()
is a method of the java.util.Map
interface whereas getValue()
is a method of the java.util.Map.Entry
interface.
I believe you can use a dictionary. Here are two ways to do the dictionary part.
or try this which uses type inference
as for the for loop
I guess it will be something like that: