Swift 条件绑定中的绑定值必须是可选类型
Swift Bound value in a conditional binding must be of Optional type
if let ip = indexPath {
var data: NSManagedObject = myList[ip.row] as NSManagedObject
cell.textLabel?.text = data.valueForKeyPath("item") as String
}
错误:
"Bound value in a conditional binding must be of Optional type"
我正在使用 xcode 6.1.1,请帮忙。
您是说:
if let ip = indexPath {
Swift 表示:"Just say let ip = indexPath
, or simply use indexPath
directly. There is no need for the if
(or the curly braces); you don't need a condition here."
原因可能是在设计您使用的教程时,indexPath
是可选的,需要解包。但现在它不是可选的。 Apple 会不时更改 API。
if let ip = indexPath {
var data: NSManagedObject = myList[ip.row] as NSManagedObject
cell.textLabel?.text = data.valueForKeyPath("item") as String
}
错误: "Bound value in a conditional binding must be of Optional type"
我正在使用 xcode 6.1.1,请帮忙。
您是说:
if let ip = indexPath {
Swift 表示:"Just say let ip = indexPath
, or simply use indexPath
directly. There is no need for the if
(or the curly braces); you don't need a condition here."
原因可能是在设计您使用的教程时,indexPath
是可选的,需要解包。但现在它不是可选的。 Apple 会不时更改 API。