如果将以下简单的代码片段放入 Playground 中:
import Foundation
let humanReadableNames = [
"test": NSLocalizedString("foo")
]
你会得到编译器错误:
Cannot confer the expression's type 'Dictionary' to type 'DictionaryLiteralConvertible'
Swift 函数 NSLocalizedString
定义为返回 String
,所以我不明白为什么这个变量的类型不只是 Dictionary<String, String>
.
最佳答案
看来您需要将注释参数添加到 NSLocalizedString() 中。
let humanReadableNames = [
"test": NSLocalizedString("foo", comment:"bar")
]
关于swift - 在 Swift 中,什么是 DictionaryLiteralConvertible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24072305/