[英]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.