繁体   English   中英

类型'string'不符合协议NilLiteralConvertible

[英]Type 'string' does not conform to protocol NilLiteralConvertible

在我的Swift代码中:

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    let stringIdent = String(format: "section_1_%d", section)
    return NSLocalizedString(stringIdent, comment: nil)
}

运行构建时出现错误:

类型'string'不符合协议NilLiteralConvertible

此代码始终在Objective-C中有效。

Swift可能有什么问题?

comment被声明为String而不是String? 你不能在那里使用nil 请改用""

 return NSLocalizedString(stringIdent, comment: "")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM