10

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?

1 Answer 1

9

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

 return NSLocalizedString(stringIdent, comment: "")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.