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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:10:48+00:00 2026-06-05T12:10:48+00:00

Worrying about duplicates but can not seem to find and answer I can understand

  • 0

Worrying about duplicates but can not seem to find and answer I can understand in any of the other posts, I just have to ask:

When I have in my .h:

@interface SecondViewController : UIViewController{    
NSString *changeName;    
}

@property (readwrite, retain) NSString *changeName;

then in my .m

@synthesize changeName;

-(IBAction)changeButton:(id)sender{
changeName = @"changed";
}

Is it the synthesized property or the instance variable that get changed when I press “changeButton” ?

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

    You (and it seems some of the others that answered) are confusing properties with actual variables.

    The way properties work is, they create METHODS (called setter and getter) that set or get/return ivars. And the do notation (self.string) actually INVOKES these methods. So a property can’t be CHANGED, only the declared iVar is.

    When you declare a property like so:

    @property (nonatomic, retain) NSString *string;
    

    And @synthesize it the following happens:

    • An iVar called string (of type NString*) is created

      (if you do

      @synthesize string = whateverYouWant
      

      the iVar created
      is called whateverYouWant – a convention is to name the iVars
      the same as the property with preceding underscore (_string))

    • an accessor method is created like this

      -(NSString*) string;
      
    • a setter is created like this

      -(void) setString: (NSString*) newString;
      

    Now what self.xxxx does is, it actually sends the message xxxx to self
    (like [self xxxx]).
    It works with ANY method, not just properties, though it should only
    Be used with properties.

    So when you do self.string = @”hello” it actually comes down to

    [self setString: @"hello"];
    

    (Note that the compiler actually knows you are trying to set and so the
    setString message is sent instead of just string. If you accessed self.string
    it would send [self string])

    Thus you don’t SET a property, you invoke the (synthesized) setter method that in
    itself sets the iVar.

    Accessing your iVar directly is ok, if you know what your doing.
    Just calling

    string = @"something else";
    

    Will produce leaking code, since no memory management is done.
    The synthesized accessors and setters actually do this for you, depending
    on how you defined th property (retain,copy,assign).

    Because the setter (for a retained property) doesn’t just do

    IVar = newValue
    

    If you declared a retained property it actually looks something like this:

    -(void) setString: (NSString*) newString {
      if (string) [string release];
      string = [newString retain];
     }
    

    So the property synthesize takes a bit of work off your hands.

    EDIT

    Since it still doesn’t seem clear, the property that is declared is not to be thought
    of like a variable. In the above example, when using

    @synthesize string = _string;
    

    there IS NO variable called “string”. It’s just the way you access the method structures
    that set the iVar _string through the setter methods. Since string is no variable/object pointer, you cannot send messages to it ([string doSomething] won’t work).
    When you just synthesize the property using @synthesize string; the generated iVar gets
    the same name as the property.
    Calling [string doSomething] will then work, but it has nothing to do with the property. The “string” refers to the iVar. Hence th convention to name the iVars underscored, so
    you don’t accidentally access the iVar when you meant to use the getter/setter.

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

Sidebar

Related Questions

Maybe it's not worth worrying about in this scenario, but lets say you have
I'm probably worrying about wrong optimization, but I have this nagging thought that it's
I'm just starting on Python and maybe I'm worrying too much too soon, but
In python I can construct a HTML string without worrying about escaping special characters
I'm trying to create a Login page, not worrying about actually logging in yet,
See thread title. Can I safely do something like that without worrying about a
I am not worrying about finding the duplicate value as much anymore. I've made
I have a self-contained solution (non of the DLLs are used in any other
Can REST be purely used as a lightweight SOAP alternative (without really worrying about
From a high-level standpoint (meaning only worrying about the results and the interface, not

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.