如何转换 [String: Any]
至[String: String]
在 swift 。我试过这样投,但没有帮助:
for (key, value) in dictionary {
dictionary[key] = value as! String
}
最佳答案
这是安全的方法,转换后的将仅包含 [String: String],非字符串 Any 将被丢弃:
let converted = dictionary.compactMapValues { $0 as? String }
关于ios - 转换 [字符串 : Any] to [String: String] in swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61835770/