Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'string' does not conform to protocol NilLiteralConvertible

Tags:

ios

swift

In my code in 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

This code always worked in Objective-C.

What could be wrong in Swift?

like image 686
Andrey Avatar asked Sep 27 '14 11:09

Andrey


1 Answers

comment is declared as String and not String?. You cannot use nil there. Use "" instead.

 return NSLocalizedString(stringIdent, comment: "")
like image 170
Kirsteins Avatar answered Sep 21 '22 06:09

Kirsteins