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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:33:06+00:00 2026-05-22T01:33:06+00:00

I am fairly far along developing a reasonably ambitious first iPhone project and I

  • 0

I am fairly far along developing a reasonably ambitious first iPhone project and I am confused as to which way to implement and access properties and why.

Example 1:
(in the .h)

Nsstring *_sale;
@property (nonatomic, retain) NSString *sale;

(in the .m)

@synthesize sale = _sale;

Example 2:
(in the .h)

@property (nonatomic, retain) NSString *sale;

(in the .m)

@synthesize sale;

Both of these seem to work to me without trouble but I am trying to figure out why there are two ways to do this and what benefits there may be to either.

Can someone tell me the difference?

  • 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-22T01:33:06+00:00Added an answer on May 22, 2026 at 1:33 am

    Example 1 demonstrates the old way of defining ivar/property variable pairs. The new compiler now generates ivars (the NSstring *_sale; part) for you. Example 1 also demonstrates manually pairing up the property sale to the ivar _sale using the @synthesize sale = _sale; statement.

    Example 2 is a more concise way to implement properties in Obj-C and is the way you will see most example code on the internet. The vast majority of the time you can write your properties without needing to overwrite the accessor/mutator methods generated for you by the compiler.

    There are some die-hard proponents of the underscore prefix to denote instance variables for clarity’s sake. You may find that this helps you when it comes to memory management, as in Example 1, setting self.sale equal to an autoreleased NSString would be fine since it would get retained, but setting _sale equal to an autoreleased object would result in erratic behavior later on because the NSString passed in would not be retained by the instance variable.

    In general, I prefer writing my properties as you have shown in Example 2.

    Short Answer: There are two ways of doing this because the new compiler now can infer some stuff for you, but the previous way of doing things has been left in for backwards compatibility.

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

Sidebar

Related Questions

I'm fairly new to python and following along with part 4 of the tutorial
I'm contributing to a fairly small open source project hosted on Github. So that
I am fairly new to qTip and so far things look awesome for implementing.
I am fairly new to Jquery and javascript and have jumped in head first
I am fairly new to iPhone/ObjC programming, though I have several years of experience
I'm fairly new to usercontrols. So far, I've found them quite useful for handling
I'm fairly new to Hibernate and PostgreSQL, but so far it's going well, although
Maven has a fairly standardized project structure and standard plugins for compilation and testing.
I'm fairly new to Drupal ... I've learned my way around a bit and
Being fairly new to JavaScript, I'm unable to discern when to use each of

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.