Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse/Swift Issue with tableviewcell "binary operator '==' cannot be applied to operands of type cell and nil"

I've an issue with Parse/Swift using Xcode 6.3 beta

    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
    }

The Error pointed to

 if cell == nil
        {
            cell = secTableViewCell(style: UITableViewCellStyle.Default , reuseIdentifier: "cell")
        }

binary operator '==' cannot be applied to operands of type cell and nil"

like image 791
James Moriarty Avatar asked Mar 11 '15 16:03

James Moriarty


1 Answers

cell is of type secTableViewCell not secTableViewCell? (Optional<secTableViewCell>). Because it's not an optional, it cannot be nil.

If you need to test for nil, then you want to have

var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as? secTableViewCell

The thing is you should never have to test for nil. "cell" should always be the same type (in your case it should alway be secTableViewCell.

like image 148
Jeffery Thomas Avatar answered Nov 17 '22 12:11

Jeffery Thomas