类型“串”不符合协议NilLiteralConvertible
问题描述:
在我的代码在斯威夫特:类型“串”不符合协议NilLiteralConvertible
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let stringIdent = String(format: "section_1_%d", section)
return NSLocalizedString(stringIdent, comment: nil)
}
我出运行的版本时出现错误:
类型“串”不符合协议NilLiteralConvertible
此代码一直在Objective-C中工作。
Swift中可能出错的是什么?
答
comment
被宣布为String
而不是String?
。那里不能使用nil
。改为使用""
。
return NSLocalizedString(stringIdent, comment: "")