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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:05:34+00:00 2026-06-13T17:05:34+00:00

To my understand self refers to the current class and when i use a

  • 0

To my understand self refers to the current class and when i use a dot after self is to use one of its properties. In the code here there’s a use in self.popOperand that i don’t understand if popOpernad is not a property. Another thing i don’t understand is why
[self pushOperand:result]; works and [self.pushOperand:result]; doesn’t.

#import "Calcbrain.h"
@interface Calcbrain()

@property (nonatomic,strong) NSMutableArray *operandStack;


@end


@implementation Calcbrain
@synthesize operandStack  = _operandStack;

-(NSMutableArray *) operandStack
{
    if(_operandStack == nil) _operandStack = [[NSMutableArray alloc]init];
    return _operandStack;
}
-(double)popOperand
{
    NSNumber *objectNum = [self.operandStack lastObject];
    if (objectNum)[self.operandStack removeLastObject];
    return [objectNum doubleValue];

}
/*-(void) setOperandStack:(NSMutableArray *)operandStack
{
    _operandStack = operandStack;
}*/

-(void)pushOperand:(double)opernand
{
    [self.operandStack addObject:[NSNumber numberWithDouble:opernand]];

}
-(double)performOperation:(NSString *)operation
{
    double result=0;

    if([operation isEqualToString:@"+"])
    {
        result = self.popOperand + self.popOperand;
    }
    else if ([@"*" isEqualToString:operation])
    {
        result = self.popOperand * self.popOperand;
    }
    [self pushOperand:result];

    return result;
}


@end
  • 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-13T17:05:35+00:00Added an answer on June 13, 2026 at 5:05 pm

    Whilst the . notation is primarily used for properties, it can be used for paramaterless methods that return a value. Why? Because the synthesised getter for a property is in the same form.

    -(double)calcValue {
        ....
        return value;
    }
    

    Is equivalent to the property declaration:

    @property (nonatomic, readonly) double calcValue;
    

    Whilst there may be no property declaration, it doesn’t mean the . notation cannot be used. The compiler will effectively change . notation to a method call when compiling, as . is a form of syntactic sugar. As so:

    self.popOperand
    // Translates to
    [self popOperand];
    

    This leads on to part 2, why does [self.pushOperand:result]; not work? The reason being is that . does not support the passing of parameters directly.

    The only way to assign/push a parameter to a property is via self.pushOperand = result, but this wouldn’t work, because there isn’t a corresponding - (void)setPushOperand:(double)pushOperand; that the . notation assignment maps to.

    [self pushOperand:result]; works because you’re being explicit in calling a particular method, called pushOperand:.

    Overall, keep . notation for properties only, and if you’re using a method that isn’t designed to be a ‘property’, be explicit.

    Update: self is a reserved keyword, that represents a pointer to the instance we’re working within at that time.

    For example, I can create two instances of Calcbrain outside of Calcbrain, for example BrainViewController:

    Calcbrain* instance1;
    Calcbrain* instance2;
    

    Now, Calcbrain has methods declared within it, let’s use -(double)performOperation:(NSString *)operation as an example. Now, if I wanted to call that from BrainViewController, I would do:

    [instance1 performOperation:@"+"];
    [instance2 performOperation:@"+"];
    

    Because we are calling a method which is part of another class, I have to determine the correct instance I’ve created to refer to it (i.e. instance1 and instance2). But how would I call that from within the class itself, and make sure it applies to the correct instance? The instance I’ve created is unaware of the other instances I’ve created. Use self. self allows you to reference yourself within methods. So if I wanted to performOperation within Calcbrain itself, I would need to use self:

    [self performOperation:@"+"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From what I understand about self , it refers to the current instance of
I would like to understand what class << self stands for in the next
I tried to understand this line of code, but it is failed. $this->request->{self::FLAG_SHOW_CONFIG} ===
What is self join and when would you use it? I don't understand self
OK so my question is self explanatory, here is some code so you can
From what I understand I should always use self.property_name everywhere except in getter and
I am self learning haskell from here . I do not understand anything when
I'm trying to understand when to use self.method_name vs. when to use Classname.method_name. In
How secure is it to use self-signed certificates? As far as I understand it,
I don't understand the need for self-joins. Can someone please explain them to me?

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.