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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:41:29+00:00 2026-06-16T16:41:29+00:00

Why in the newest version of Xcode (dp-4) are variables declared with retain,nonatomic made

  • 0

Why in the newest version of Xcode (dp-4) are variables declared with retain,nonatomic made to use the underscore before the variable name? Does this create some sort of type safety?

For example, I create a property:

@property (retain, nonatomic) IBOutlet UILabel *name;

Unless I change the variable inside the dealloc to not have the _, I have to do:

@synthesize name = _name;

Why is this?

  • 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-06-16T16:41:30+00:00Added an answer on June 16, 2026 at 4:41 pm

    Mark Dalrymple, who’s way smarter than I am, wrote a blog post at Big Nerd Ranch about this very subject. Bottom line: the underscore is a good idea. I will summarize his post here just in case the link stops working in the future, but if possible you should read his post instead of my summary.

    He wrote this post back when explicitly calling @synthesize was mandatory. He advocated code such as:

    // soapbubble.m
    @synthesize viscosity = _viscosity;
    @synthesize detergentBrand = _detergentBrand;
    

    These days Xcode automatically and implicitly includes @synthesize. And it does so using the prepended underscore so apparently Apple’s engineers agree with Mark.

    His first reason is stylistic. It allows you to easily see which variables are local and which are arguments in a setter:

    - (void) setPonyName: (NSString *) ponyName {
        [_ponyName autorelease];
        _ponyName = [ponyName copy];
    }
    

    (This is a pre-ARC setter, so now this method would be completely unnecessary, but if the setter did anything more involved than simply releasing and assigning a value it would still apply.)

    His second reason (and the one I think is more important) is that eliminates a certain class of bug that can be very difficult to track down.

    This code:

    self.ponyName = @"Mikey";
    

    is identical to:

    [self setPonyName: @"Mikey"];
    

    Without the prepended underscore, this code is also valid:

    ponyName = @"Mikey";
    

    but it doesn’t call the setter so any side effects in the setter don’t occur. Again, in a situation where the setter does extra work besides changing the local variable’s value this can cause big headaches. With the prepended underscore, that line would cause a compile error. You would have to be very explicit about wanting to set a local variable:

    _ponyName = @"Mikey";
    

    and, being the conscientious programmer you are, you would include a comment explaining exactly why you are performing this irregular maneuver.

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

Sidebar

Related Questions

This should be easy.. I recently upgraded to the newest version of Xcode on
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I am trying to use YAF with Umbraco. The newest version out changed enough
I installed the newest version of Xcode. Neither of the executables gcc , cc
I installed the newest version of Windows 7. This is my development box, so
I have just started to use the newest version of S#arp Architecture 1.9.5, which
I would like to use the newest version, but can't use anything dependent on
Hello: Does anyone know how to paste as Word into the newest version of
I want to use the newest version of Python on Snow Leopard using the
Im developing an iOS application using the newest version of Xcode. The application are

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.