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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:35:08+00:00 2026-06-06T21:35:08+00:00

In Objective C what scenario would I want to use [self setVariable:value]; instead of

  • 0

In Objective C what scenario would I want to use [self setVariable:value]; instead of variable = value;

It seems as if doing a self set I’m saving myself few lines of code, but what other advantages are there? Additionally, when would I NOT want to do a self set?

  • 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-06T21:35:11+00:00Added an answer on June 6, 2026 at 9:35 pm

    EDIT:
    I should clarify, that what I am referencing below is strictly in regards to variables that are properties. If a variable is just an ivar, then there is no difference between self.variable = value or variable = value, other than the fact that self.variable = value will not even compile if it is just an ivar, in that case you need to use self->variable = value

    Calling

    [self setVariable:value];
    

    is the same as calling

    self.variable = value;
    

    This, however, is NOT the same as

    variable = value;
    

    The first two cases use the synthesized setVariable method (or the one you defined yourself). The reason you would want to use this is to make sure you keep the proper retain count on your objects.

    For example, a simple property such as:

    @property (retain) NSString *myString;
    

    Gets an automatically generated set function that looks something like:

    -(void) setMyString:(NSString*)other
    {
        myString = [other retain];
    }
    

    If you were to just call

    myString = otherString;
    

    elsewhere in your code, then myString is not retained properly, so if otherString gets deallocated, your pointer to that object is no longer valid.

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

Sidebar

Related Questions

Objective: I want to create a web service that allows me to connect to
Scenario: I've hundreds of applications instances running on client machines doing a certain job.
Is it the normal practice in objective c to use the controller as the
What is the nce between accessing a property via propertyname versus self.propertyname in objective-c?
I want to know if this is inherently possible: Think of a cloud scenario.
We have a scenario where we need to use the Quickbooks SDK to create
I run into a fairly common scenario in Objective-C where I pass in a
Objective-C uses a sophisticated message-passing system when one object calls a method on another
Objective: In support of a Windows Service that may have multiple instances on a
Objective: My script will download a remote file upon form submission, since the file

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.