小编Juv*_*tus的帖子

什么是Swift中的Java HashMap <String,Integer>

我有一个用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接口的方法.

java dictionary swift swift3

13
推荐指数
2
解决办法
2万
查看次数

Swift 等价于 Java 中的 Enum.ordinal()

我想知道是否有 JavaEnum.ordinal()方法的 Swift 等价物。

java enums swift

3
推荐指数
1
解决办法
1112
查看次数

什么是Java比较器接口的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)

swift

2
推荐指数
2
解决办法
1429
查看次数

标签 统计

swift ×3

java ×2

dictionary ×1

enums ×1

swift3 ×1