类型'string'不符合协议NilLiteralConvertible

And*_*rey 10 ios swift

在我的Swift代码中:

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

运行构建时出现错误:

类型'string'不符合协议NilLiteralConvertible

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

Swift可能有什么问题?

Kir*_*ins 9

comment宣称String是否String?.你不能nil在那里使用.请""改用.

 return NSLocalizedString(stringIdent, comment: "")
Run Code Online (Sandbox Code Playgroud)