2014-09-27 102 views
9

在我的代码在斯威夫特:类型“串”不符合协议NilLiteralConvertible

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

我出运行的版本时出现错误:

类型“串”不符合协议NilLiteralConvertible

此代码一直在Objective-C中工作。

Swift中可能出错的是什么?

回答

9

comment被宣布为String而不是String?。那里不能使用nil。改为使用""

return NSLocalizedString(stringIdent, comment: "") 
相关问题