我有一个用Java编写的示例,我想将其转换为Swift.下面是代码的一部分.如果你能提供帮助我真的很感激.
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();
...
}
Run Code Online (Sandbox Code Playgroud)
注意:entrySet()是java.util.Map接口getValue()的方法,而java.util.Map.Entry接口的方法.
我想知道是否有 JavaEnum.ordinal()方法的 Swift 等价物。
我在下面的Java代码中尝试将其相应地转换为Swift。有人可以帮我解决这个问题。谢谢
public class CarsSortById implements Comparator<Cars>{
@Override
public int compare(Cars car1, Cars car2) {
return (car1.getCarId() < car2.getCarId()) ? -1:
(car1.getCarId() > car2.getCarId() ) ? 1:0 ;
}
}
Run Code Online (Sandbox Code Playgroud)