dictionaryWithObjects: forKeys: 在 swift 中的确切替代品

the exact replacement for dictionaryWithObjects: forKeys: in swift

我正在将代码从 objective c 转换为 swift,我找不到 dictionaryWithObjects: forKeys: 的替代品,我尝试的任何东西都没有给出预期的输出。

我试过了dict.updateValue(values[i]!, forKey: keys[i] as! String ) 在 for 循环中,但我意识到 keys(26) 中没有常量元素,但对于 values(20,000) 它有很多元素。 所以请帮帮我!! 对不起,如果我错了,提前致谢。

for i in 0..<alphabets.count {  
  in_memory_prediction.updateValue(prediction[i]!, forKey: alphabets[i] as! String) 
}

即使值为对象,您也应该可以直接更新字典

var eachKey = alphabets[i] as! String
in_memory_prediction[eachKey] = prediction[i]!