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

  • Home
  • SEARCH
  • 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 7588473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:55:42+00:00 2026-05-30T19:55:42+00:00

I stumbled upon this post In Objective-C why should I check if self =

  • 0

I stumbled upon this post In Objective-C why should I check if self = [super init] is not nil?

I can understand this syntax:

- (id)initWithString:(NSString *)aString
{
    self = [super init];
    if (self)
    {
        instanceString = [aString retain];
    }
    return self;
}

or this syntax:

- (id)init;
{
 if (!(self = [super init]))
   return nil;

 // other stuff
 return self;
}

but I still don’t understand the “standard” template syntax

- init {
    if((self = [super init])) {
        // set up instance variables and whatever else here
    }
    return self;
}

Can someone tell as clearly as possible what (3) does more or less compared to (1) or (2) ? All I read is so confusing (why people can’t agree with something which is purely technical seems like politics :))

Nevertheless as I read authors article, and as I can fuzzily understand it goes far beyond just syntactic sugar debate or matter of taste. For example it is said:

Curiously then, while case 3 is overwhelmingly more common, initializers that support 1, 2 and 4 but are incompatible with case 3 have become the standard.Curiously then, while case 3 is overwhelmingly more common, initializers that support 1, 2 and 4 but are incompatible with case 3 have become the standard.

So I’d like to have a deep philosophical answer from Objective C Gurus if possible.

  • 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-30T19:55:43+00:00Added an answer on May 30, 2026 at 7:55 pm

    The key to understanding (3) is the if line

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

    In C, every operator has a return value, you just don’t have to use it. So just as 3 + 4 returns 7, the operator = returns the same value that was just assigned. That allows you to do interesting things like this with it:

    int a, b, c, d;
    
    a = b = c = d = 5;
    

    (This works because the operator has right-to-left associativity. This means that a = b = 3;is equivalent to a = (b = 3); so b is set to three first, then a is set to that same value.)

    So now we can observe that the test

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

    is exactly the same as

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

    They all do exactly the same thing, though. As for the preferred option, a lot of people think that putting expressions into if statements is bad practice, as it’s hard to notice if you’re not used to it. Apple do seem to have settled with the first example you listed in their templates, and have also added a compiler warning for the first, if you try to do it without the stupid double brackets if(()).

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

Sidebar

Related Questions

I stumbled upon this while doing a review and the author is not available:
I stumbled upon this issue with parseInt and I'm not sure why this is
I just stumbled upon this issue and i can't think of a solution I
I stumbled upon this post while researching on the Delete Directory options available under:
I stumbled upon this many times, never found a solution. A UINavigationController's navigationBar can
I just stumbled upon this blog post about cache algorithms. The author shows two
I stumbled upon that word in this blog post . There is similar question
I stumbled upon this code and I am curious as to what use may
I stumbled upon this question: 7 power 7 is 823543. Which higher power of
I got stumbled upon this issue once and I guess I need some expertise

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.