Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 824903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:10:10+00:00 2026-05-15T03:10:10+00:00

Pretty much everyone that writes about the UISplitView on the iPad uses the following

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:10:11+00:00Added an answer on May 15, 2026 at 3:10 am

    In this case, it’s not important and just adds a line of code.

    However, when the return type of a method is not an integral type, this check can be important. Oh crap, it seems they fixed that in ObjC 2.0.

    It’s important to check for nil when a non-scalar type should be returned. Take this example:

    struct complex_t
    {
        int foo, bar, frob;
        double nicate;
    };
    
    @interface Foo : NSObject {}
    -(struct complex_t)complex;
    @end
    
    @implementation Foo
    -(struct complex_t)complex { return (struct complex_t){-1, 2, -1, 1e14}; }
    @end
    
    int main()
    {
        struct complex_t c;
        memset(&c, 0xFFFFFFFF, sizeof c);
        c = [nil complex];
        printf("%i %i %i %g\n", c.foo, c.bar, c.frob, c.nicate);
    }
    

    In this example, our c is happily memset to have -1s in every field (except for the double, which I don’t quite know what it does). Messaging nil indeed resets everything to zero.

    But wait!

    Just suppose we change our main a little bit:

    int main()
    {
        struct complex_t c;
        memset(&c, 0xFFFFFFFF, sizeof c);
        [[[Foo alloc] init] complex]; // NEW LINE HERE!
        c = [nil complex];
        printf("%i %i %i %g\n", c.foo, c.bar, c.frob, c.nicate);
    }
    

    It now happens that c will hold what [[[Foo alloc] init] complex] returned, even though the return value was technically not used. (EDIT Compiled from gcc -lobjc -framework Cocoa as an x86_64 binary. Your mileage may vary with your architecture.)

    It seems the return value of a big struct when messaging nil is undefined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: So pretty much everyone here has told me that I just need to
The following blocks of code are pretty much the same... the main diffirence between
this pretty much is the thing. When in tinymce I press anything that is
Pretty much everyone and every tutorial seems to store it's private app data in
edit: To prevent everyone from reading too much: The problem is that i do
Pretty much I need to detect when the scrollView is at 320 x to
Pretty much as the title says, if I put an image inside a details
Pretty much the opposite of server-side push, also known as Comet . I'm wondering
Pretty much the same as this question. But I can't seem to get this
Pretty much what it says on the tin. I've tried googling around but can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.