简体   繁体   中英

Type 'string' does not conform to protocol NilLiteralConvertible

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?

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

 return NSLocalizedString(stringIdent, comment: "")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM