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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:25:17+00:00 2026-05-26T18:25:17+00:00

Possible Duplicate: Difference between class property mVar and instance variable self.mVar I am new

  • 0

Possible Duplicate:
Difference between class property mVar and instance variable self.mVar

I am new to developing in Objective-C and I couldn’t quite figure out what the difference is between the following:

First let me explain my situation. I’ve got an NSMutableArray, and I created and outlet for it in my .h file. Now when I assign an array to it as

self.myMutableArray=myArray

I get an error; However just

myMutableArray=myArray

works fine.

I am not interested in the resolving of the error. I just want to know what is the difference when putting self in front of something? And why I am able to use the variable also without self and what restrictions that brings with it?

  • 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-26T18:25:17+00:00Added an answer on May 26, 2026 at 6:25 pm
    self.property = value;
    

    is equal to:

    [self setProperty:value];
    

    That is to say, the declaration using self. goes through the object’s accessor method, rather than using direct access.

    They have different causes and effects. Perhaps the most notable is that direct access will often leads to reference count issues (leaks/zombies) if not used with care. The accessor is responsible for handling memory management – if synthesised, or if you implement it yourself.

    The General Rule: You should favor using the accessors (self.blah = thing;) over direct access (blah = thing;) until you know when and why you would make exceptions to this rule.

    The immediate exception: There is one exception to the general rule: Do not use the accessors in partially constructed states, such as the object’s initializer or dealloc. In those cases, use direct access:

    - (id)init
    {
      self = [super init];
      if (0 != self) {
        things = [NSArray new];
      }
      return self;
    }
    
    - (void)dealloc << not needed with ARC, in this case
    {
      [things release], things = 0;
      [super dealloc];
    }
    

    Update

    Describing Bavarious’ suspicion of the error:

    It sounds like you have declared an instance variable, but have not declared an associated property or proper accessors (e.g. the setter). Here’s a breakdown of a class’ declaration with ivars and properties:

    @interface MONObject : NSObject
    {
    @private
      NSMutableArray * myMutableArray; << declares an instance variable
    }
    
    // the property declaration:
    @property (nonatomic, retain, readwrite) NSMutableArray * myMutableArray;
    // adds the accessors:
    //   - (NSMutableArray *)myMutableArray; << getter
    //   - (void)setMyMutableArray:(NSMutableArray *)arg; << setter
    // to the class' interface.
    
    @end
    
    
    @implementation MONObject
    
    // @synthesize below generates the accessors for the property
    // myMutableArray, using "myMutableArray" ivar by default.
    @synthesize myMutableArray;
    
    - (void)zumBeispiel
    {
      NSUInteger count = 0;
    
      // direct access:
      count = [myMutableArray count];
      // is equal to:
      count = [self->myMutableArray count];
    
      // Access via the getter:
      count = [self.myMutableArray count]; << equal to [self myMutableArray]
      // is equal to:
      count = [[self myMutableArray] count];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is the difference between "typename" and "class" template parameters? When defining
Possible Duplicate: Difference between pointer variable and reference variable in C++ When should I
Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading
Possible Duplicate: C#: Difference between ‘ += anEvent’ and ‘ += new EventHandler(anEvent)’ Hi
Possible Duplicate: JavaScript: Class.method vs. Class.prototype.method What's the difference between creating a prototype like
Possible Duplicate: Interface vs Base class I am not understanding the difference between an
Possible Duplicate: PHP: What is the difference between an interface and abstract class? As
Possible Duplicate: What is difference between instantiating an object using new vs. without This
Possible Duplicate: What is the difference between a field and a property in C#
Possible Duplicate: What is the difference between a template class and a class template?

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.