在我的 Swift 代码中:
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let stringIdent = String(format: "section_1_%d", section)
return NSLocalizedString(stringIdent, comment: nil)
}
运行构建时显示错误:
Type 'string' does not conform to protocol NilLiteralConvertible
此代码在 Objective-C 中始终有效。
Swift 有什么问题?
最佳答案
comment
声明为 String
而不是 String?
。你不能在那里使用 nil
。请改用 ""
。
return NSLocalizedString(stringIdent, comment: "")
关于ios - 类型 'string' 不符合协议(protocol) NilLiteralConvertible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26074398/