Why check if your popoverController is nil? Doesn't Obj-C ignore messages to nil?
- by Rob Fonseca-Ensor
Pretty much everyone that writes about the UISplitView on the iPad uses the following code structure to dismiss a popover:
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
}
I though Objective-C was happy to ignore messages that are passed to nil? In fact, in the File New Project New Split View Application template, there's an example of this shortcut in the same code block (DetailsViewController.m):
- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
[detailItem release]; //might be nil
detailItem = [newDetailItem retain];
// Update the view.
[self configureView];
}
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES]; //was checked for nil
}
}
Why is that second if necessary?