0

While using tableViews, I have seen this code lots of times.

    static NSString* CellIdentifier = @"Cell";    
    UITableViewCell* cell = [tableView dequeue...:CellIdentifier];

    if( cell == nil )    /* note the expression used in the conditional */
    {
        // do stuff
    }

I have also seen the same idea expressed as follows.

    static NSString* CellIdentifier = @"Cell";    
    UITableViewCell* cell = [tableView dequeue...:CellIdentifier];

    if( !cell )    /* note the expression used in the conditional */
    {
        // do stuff
    }

In my understanding, these are the same. In the first example, the == operator will return if the cell is nil. The second conditional will also only be true if the cell is nil. Why is there a discrepancy in the method used to test the cell? Will these conditionals ever return different things?

Brian Tracy
  • 6,801
  • 2
  • 33
  • 48

1 Answers1

1

These will both give you the same result. It is more of a style preference.

Personally, I feel if (!cell) is just easier to read.

See: http://www.cimgf.com/zds-code-style-guide/

Dave Wood
  • 13,143
  • 2
  • 59
  • 67