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 938889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:42:23+00:00 2026-05-15T21:42:23+00:00

I see a lot of code like this in samples and in stubs that

  • 0

I see a lot of code like this in samples and in stubs that XCode generates:

if ((self = [super init])) {
}

I am not clear on the intention of double parenthesis in the conditional.

  • 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-15T21:42:23+00:00Added an answer on May 15, 2026 at 9:42 pm

    To expand on @Anders comment, the specific issue it’s protecting you against goes like this:

    if (foo = x) { do_something() };
    

    90% of the time this is a bug. You meant to say foo == x. But 10% of the time, you really meant “assign x to foo and then test for truth.” The canonical case of this is is while (ch = getchar()). But the if (self = [super init]) is another good example. The compiler assumes that such things are mistakes and throws a warning unless you tell the compiler you really meant it by using double parentheses.

    Personally, I just do it this way:

    self = [super init];
    if (self != nil)
    {
      ...
    }
    return self;
    

    It’s an extra line, but it keeps things just that tiny bit clearer when the init call is long.

    As an aside, Aaron Hillegass of Big Nerd Ranch fame challenged several of us to come up with any case in which this self==nil check actually mattered. The cases exist, but they are incredibly few (you might add self as an NSObservation observer and you wouldn’t want it to be nil in that case). Take it for what it’s worth; in my personal code I often skip the nil check, but in my professional code it’s part of my team’s standard.

    As another aside, for some reason Apple added an extra gcc option -Wmost that turns off this warning. I guess someone there didn’t like typing the extra parentheses. It seems a bad idea to me to turn it off.

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

Sidebar

Related Questions

In a lot of TDD tutorials I see code like this: public class MyClass
I see a lot of legacy code like this: class A { public static
I see a lot of code like this: function Base() {} function Sub() {}
I use SetTimer API and I see a lot of code like this: case
I am finding I'm writing a lot of code that looks like this: <div
I see a lot in autoconf code about stuff being dnl'ed and not dnl'ed.
I see a lot of objective-c code that just #defines local constants it needs,
This code I am looking at has a lot of places where I see
I have certain code that I want to optimize. It looks like this: function
I see a lot of code in some popular Javascript libraries that often create

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.