【发布时间】:2015-12-09 13:46:06
【问题描述】:
假设我有一个 Dictionary<String, String>,我希望有一个方便的 getter 用于实现 StringLiteralConvertible 的类型。
let items = ["Key 1": "Value 1", "Key 2": "Value 2"]
func get<T: StringLiteralConvertible>(key: String, _ defaultValue: T) -> T {
if let value = items[key] {
return T(stringLiteral: value) // BUG
}
return defaultValue
}
但是在标有BUG注释的那一行放什么呢?
【问题讨论】: