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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:32:05+00:00 2026-06-18T23:32:05+00:00

I declared a property as below. From my readings on the web, it is

  • 0

I declared a property as below. From my readings on the web, it is not clear if I should also synthesize as below. I have seen supporting blog posts for two different approaches.

@property (assign, nonatomic) CGFloat someFloat;

Then in the implementation:

@synthesize someFloat = _someFloat;

I have also seen in some cases:

@synthesize someFloat;

From readings, I understand that “someFloat” is a property name, and “_someFloat” is created through the synthesis. So I am under the impression that the first way is correct. However, I have used the second approach without problems. And I have seen the second approach in other code and blogs.

Can someone tell me what is the correct way and why?

  • 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-18T23:32:06+00:00Added an answer on June 18, 2026 at 11:32 pm

    In general, you no longer need to manually write @synthesize anymore. In your example, if you write

    @property (assign, nonatomic) CGFloat someFloat;
    

    The compiler will automatically synthesize it for you, which would be equivalent to you writing

    @synthesize someFloat = _someFloat;
    

    Hence, you would be able to access the property through self.someFloat or access the ivar within the implementation file by using _someFloat.

    If, however, you manually synthesize it like

    @synthesize someFloat;
    

    The compiler automatically creates a backing ivar titled someFloat… thereby, you would still be able to access the variable through the getter self.someFloat (that is, equivalent to [self someFloat] call).

    Or, you could access the ivar by simply using someFloat somewhere within the implementation…

    In general, it’s not recommended to synthesize like this because it’s quite easy to accidentally use the ivar when you meant to access the variable using the getter.

    EXCEPTION TO THE RULE

    The compiler still gets confused with synthesizing variables sometimes, however, in certain instances. For example, if you have a class that is a subclass of NSManagedObject, then you still need to write the @synthesize manually (assuming, of course, you actually want to synthesize the property… you likely don’t though…).

    The reason for this is two-fold: (1) the compiler doesn’t seem to understand these properties very well yet (or at least it doesn’t in the cases I’ve worked with), and (2) many times, you actually DON’T want to @synthesize properties on an NSManagedObject subclass… rather, you want them to be @dynamic instead (so the getter/setter will be generated at runtime, per requirements of NSManagedObject subclass magic).

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

Sidebar

Related Questions

I've declared a property someProperty and synthesized it: @synthesize someProperty = _someProperty; But when
I have this retained property declared like this: @property (nonatomic, retain) NSMutableDictionary *codes; then
I have an attribute declared on property. How can I get the property name
I have a div with float:right (no position property declared). This div has some
I have a @property listOfSites declared in a class. I am unable to access
I have a variable declared like this: @property (nonatomic, retain) NSMutableArray *aInfo; At the
When I declare a property in objective-C, I also add the synthesize clause to
I have an NSString which has been declared as property and being allocated and
Possible Duplicate: Detecting an undefined object property in JavaScript From the below JavaScript sample,
I have my default schema declared in persistence.xml as: <property name=hibernate.default_schema value=MYSCHEMA /> However,

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.