[英]Type 'string' does not conform to protocol NilLiteralConvertible
In my code in Swift: 在我的Swift代码中:
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let stringIdent = String(format: "section_1_%d", section)
return NSLocalizedString(stringIdent, comment: nil)
}
I am shown an error when running the build: 运行构建时出现错误:
Type 'string' does not conform to protocol NilLiteralConvertible
类型'string'不符合协议NilLiteralConvertible
This code always worked in Objective-C. 此代码始终在Objective-C中有效。
What could be wrong in Swift? Swift可能有什么问题?
comment
is declared as String
and not String?
comment
被声明为String
而不是String?
. 。 You cannot use
nil
there. 你不能在那里使用
nil
。 Use ""
instead. 请改用
""
。
return NSLocalizedString(stringIdent, comment: "")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.