XCode6Beta5: Why is "UITableViewCell" not a subtype of "NSNumber"?

I tried to implement a function cellForRowAtIndexPath

in mine ViewController

that implements the protocol UITableViewDataSource

:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    ...

    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
        var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell;
        if !cell {
            cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
        }
        cell.textLabel.text = "row \(indexPath.row)";
        cell.detailTextLabel.text = "row details \(indexPath.row)"
        return cell;
    }

      

This is a correct translation from the objective-c code side (I assume).

However the fast compiler puts this error message: "UITableViewCell" is not a subtype of "NSNumber" "

enter image description here

If I change the implementation to

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell;

    cell.textLabel.text = "row \(indexPath.row)";
    // cell.detailTextLabel.text = "row details \(indexPath.row)"
    return cell;
}

      

The compiler error is gone and the application seems to work as I expect.

My question is:

1) Why did the fast compiler issue this error message?

2) What is the correct syntax for the test variable cell

, is it null or not? Apparently NSNumber is expected soon. Is it because of the operator !

?

3) Does it make sense to check the nullity cell

? I believe that when I used as UITableViewCell

in the call dequeueReusableCellWithIdentifier

, I already ruled out the possibility of nil. Is it fast to ensure that the function dequeueReusableCellWithIdentifier

always returns a UITableViewCell? It differs from objective-c behavior.

+3


source to share


1 answer


You have to test null explicitly. See the Release Notes for XCode 6 Beta 5.

if cell != nil {
    ...
}

      



The compiler message is misleading.

Options no longer conform to the BooleanType (formerly LogicValue) protocol, so they may no longer be used in place of Boolean expressions (they must be explicitly mapped to v! = Nil).

+4


source







All Articles