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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:49:56+00:00 2026-06-05T00:49:56+00:00

Simple question I can’t seem to find a fast post for; if I have

  • 0

Simple question I can’t seem to find a fast post for;

if I have an object, lets say:

 NSString *myString_;
 @property(readwrite, retain)NSString* myString;
 @synthesize myString = myString_; 

When I synthesize this, does this alloc memory for the object?

Thanks

  • 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-05T00:49:57+00:00Added an answer on June 5, 2026 at 12:49 am

    All that @synthesize does is generate the accessors (setter and getter) for your property and create an instance variable with the same name. The added step of using the equals sign:

    @synthesize mystring = _string;
    

    … renames the instance variable for you to _string (or whatever name you choose, the underbar is just an apple convention). This is good practice since having the instance variable share the same name as the accessors can be problematic. Having the underbar lets you differentiate between the two.

    This is basically what is generated (assume ARC is ON):

    // getter
    - (NSString*)mystring
    {
        return _string;
    }
    

    and

    // setter
    - (void)setMyString:(NString*)myString
    {
        _myString = myString;
    }
    

    You can initialize you property in an init method (using self.propertyName):

    -(id)init
    {
        self.myString = @"Something"; // or use an alloc init method in the class   
    }
    

    or you can initialize it lazily by overriding the getter like so:

    - (NSString*)myString
    {
        if (!_myString) {  // same as saying if nil and therefore doesn't exist yet
            _myString = @"Something";
        }
        return _myString;
    }
    

    Also note you don’t need to declare your variable separately (i.e. you don’t need NSString* mystring). Just use strong or weak in place of retain when declaring the property.

    The only places you should access the instance variable directly is in the accessors, this allows you to control all action to it through a single gateway. The overhead of using the accessors within the class (i.e self.mystring) is infinitesimal. Of course you don’t have to do it this way, but it’s good practice.

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

Sidebar

Related Questions

Simple question which I can't seem to find an answer of: I have two
Good morning SO, So I have a simple question I can't seem to find
A very simple question I can't seem to find a definitive answer for. I
got a very simple question which I can't seem to find any answer for.
i have a very simple question I can't seem to get my head around.
Simple question, can't seem to find an answer on Google. I'm normalizing a database
simple question maybe but can't find solution. I have button for refresh/update some contents
Simple question I can't seem to find the answer to. I'm trying to squeeze
This is probably a simple question but I can't seem to find the solution.
A seemingly simple question: Can I have some sort of Number object, which can

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.