Why check if your popoverController is nil? Doesn't Obj-C ignore messages to nil?
Posted
by Rob Fonseca-Ensor
on Stack Overflow
See other posts from Stack Overflow
or by Rob Fonseca-Ensor
Published on 2010-05-31T20:52:01Z
Indexed on
2010/05/31
21:13 UTC
Read the original article
Hit count: 297
objective-c
|ipad-splitview
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?
© Stack Overflow or respective owner