2014-09-27 109 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: "") 
相關問題