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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:05:37+00:00 2026-05-13T09:05:37+00:00

In a project I’m creating, I have various classes. One of my classes has

  • 0

In a project I’m creating, I have various classes. One of my classes has an instance of NSMutableArray that holds objects of another one of my classes. I thought I had a firm understanding on this topic, but somehow it got jumbled up in my mind again.

When initializing an instance of this class, I have this initilize method:

- (MMShowMovement *) initWithMovementName: (NSString *) name andNumber: (NSInteger) number {

 if( [super init] ) {

  [self setMovementTitle: name];
  [self setMovementNumber: number];

  [self setDotArray: [[NSMutableArray alloc] init]];

 }

 return self;

}

Later on, after an instance of this class is created, I can add objects to the NSMutableArray “dotArray.” Here is that method.

- (void) addDot: (MMDot *) dot {

 [dotArray addObject: dot]; 

}

(I know, its simple) I’m wondering, when I use “dotArray” in this method, I am accessing the dotArray object for the instance of the class for which this method has been invoked, correct? Or should I use the self keyword here also?

- (void) addDot: (MMDot *) dot {

 [[self dotArray] addObject: dot]; 

}

Honestly, I’m not really sure. I believe it is the former, but I’m unsure as to why. And it is not necessary to use the self keyword in this method, why do I have to use it in the initializer to access the object?

  • 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-13T09:05:37+00:00Added an answer on May 13, 2026 at 9:05 am

    Usually we’ll write

    self = [super init]  
    

    Because super‘s initialization method might return an object that’s not the same as the one that was allocated. So that’s why we use self in initxxx method and we don’t need to use self in other kinds of methods.

    I learned this stuff clearly from the book Learn Objective-C on the Mac, Chap 10 Object Initialization, Mark Dalrymple and Scott Knaster, Apress.

    A excerpt from the book:
    instance variables are found at a memory location that’s a fixed distance from the hidden self parameter. If a new object is returned from an init method, we need to update self so that any subsequent instance variable references affect the right places in memory.

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

Sidebar

Related Questions

My project needs to have a number of administrators, out of which only one
I project I have been working on has now been split between me and
My project requires that I update the contents of a specific column in an
My project has all the visual studio solutions and projects stored in ./win/vc100, sources
A project I have been working on for the past year writes out log
Project 1: Foo Project 2: Bar If Foo depends on Bar, and both are
Project structure is: /foo pom.xml /foo-war pom.xml /foo-ear pom.xml This is my parent pom.xml
Project A depends on project B. On compilation time , everything is OK. On
The project I'm working on allows an end-user to modify CSS code to integrate
My project is made out of lots of bits and pieces of older code.

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.