Parse/Swift Проблема с бинарным оператором tableviewcell '==' не может применяться к операндам типа cell и nil "
У меня проблема с Parse/Swift с помощью Xcode 6.3 betap >
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath , object: PFObject) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! secTableViewCell
if cell == nil
{
cell = secTableViewCell(style: UITableViewCellStyle.Default , reuseIdentifier: "cell")
}
// Configure the cell...
cell.title.text = (object["exams"] as! String)
cell.img.image = UIImage(named: "109.png")
return cell
}
Ошибка указала на
if cell == nil
{
cell = secTableViewCell(style: UITableViewCellStyle.Default , reuseIdentifier: "cell")
}
двоичный оператор '==' не может применяться к операндам типа cell и nil "
Ответы
Ответ 1
cell
имеет тип secTableViewCell
not secTableViewCell?
(Optional<secTableViewCell>
). Поскольку он не является необязательным, он не может быть равен нулю.
Если вам нужно протестировать nil
, то вы хотите иметь
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as? secTableViewCell
Дело в том, что вам никогда не придется тестировать nil
. "ячейка" всегда должна быть одного типа (в вашем случае она всегда должна быть secTableViewCell
.