![](/img/trans.png)
[英]type [String: String] does not conform to protocol 'AnyObject'
[英]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.