Bugs in "Your Second iOS App: Storyboards" tutorial

Originator:kristopherdjohnson
Number:rdar://12449693 Date Originated:07-Oct-2012 09:11 AM
Status:Open Resolved:
Product:Documentation Product Version:iOS 6 SDK
Classification:Serious Bug Reproducible:Always
 
07-Oct-2012 09:11 AM Kristopher Johnson:
Summary: If the code presented in the tutorial "Your Second iOS App: Storyboards" is used as-is, the app will not work. It crashes. The code contains several bugs.

For example, this is the implementation of -[tableView:cellForRowAtIndexPath:] presented in the tutorial:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
    static NSString *CellIdentifier = @"BirdSightingCell";
 
    static NSDateFormatter *formatter = nil;
    if (formatter == nil) {
        formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterMediumStyle];
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 
    BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row];
    [[cell textLabel] setText:sightingAtIndex.name];
    [[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate *)sightingAtIndex.date]];
    return cell;
}

When the app is run, [tableView dequeueReusableCellWithIdentifier:CellIdentifier] returns nil, because no reusable cell is ever created. So the debugger reports an exception:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

There are several other non-crashing bugs. For example, properties are declared with the "copy" attribute, but initializers and property setters simply set a reference rather than performing a copy.

The tutorial also contains dubious advice, like "Although you can delete the unnecessary code, it’s often better to use the multiline comment symbols to make the code invisible to the compiler (the multiline comment symbols are /* and */). Commenting out code that you don’t need makes it easier to change the implementation of your app in the future." Many developers believe that leaving commented-out code in place is a very poor practice.

Steps to Reproduce:

- Read the "Your Second iOS App Tutorial: Storyboards" at http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/SecondiOSAppTutorial/Introduction/Introduction.html

- Follow the instructions in the tutorial, copying the code from the tutorial and pasting into your own app.

- Run the app.  It will crash.


Expected Results: Tutorial code should work correctly.

Actual Results: Tutorial code crashes

Regression:

Notes: See discussion at https://discussions.apple.com/message/19926327

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!