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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:25:34+00:00 2026-06-05T14:25:34+00:00

Question 1: how do I have an instance variable make a permanent copy of

  • 0

Question 1: how do I have an instance variable make a permanent copy of a value that changes (in this case, self.display.text) instead of a pointer?

Question 2: is my terminology correct in how I stated the problem?

I’m starting up with Obj-c for a few weeks now and I’ve come across this problem. I think part of the problem is that I do not know the correct terminology (and therefore it’s hard to search for a solution). So here it goes:

This is a basic calculator program:
    1)User inputs their first number
    2)User presses an action (+, -, *, /)
    2a) first inputted number is saved; display is reset
    3)User inputs second number
    4)User presses enter
    4a) second inputed number is saved; action is performed on the first and second number

This declares my CalculatorViewController.h

@interface CalculatorViewController : UIViewController
@property double firstNumber, secondNumber, result;
@property int actionType;
@property (weak, nonatomic) IBOutlet UILabel *display;
@property BOOL userIsInTheMiddleOfEnteringANumber;
@end



Implementation here...
// method for when someone clicks an action item on the calculator (such as +, -, *, /)
- (IBAction)pressedAction:(UIButton *)sender {

self.firstNumber = [self.display.text doubleValue];

(action type is set here)

NSLog(@"Action Type: %i", self.actionType);
NSLog(@"FN: %f, SN: %f", self.firstNumber, self.secondNumber);

}

// method for when someone clicks enter (and therefore firstNumber and secondNumber are set
- (IBAction)pressedEnter {
self.secondNumber = [self.display.text doubleValue];

NSLog(@"f: %f, s: %f", self.firstNumber, self.secondNumber);
// should do the given action to the self.firstNumber, self.secondNumber here

}

Here’s my problem: firstNumber is being set as a pointer (terminology?) to the self.display.text (which is the label / output on the screen) instead of being a permanent copy at the time of assignment. Therefore, when the number changes after someone has clicked plus, the firstNumber is being changed as more numbers are being inputted.

Thanks for the help! I really appreciate 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-06-05T14:25:35+00:00Added an answer on June 5, 2026 at 2:25 pm

    Here’s my problem: firstNumber is being set as a pointer (terminology?) to the self.display.text (which is the label / output on the screen) instead of being a permanent copy at the time of assignment.

    That cannot be true. firstNumber is a double, not a pointer. If self.display.text changes afterwards, firstNumber will not change.

    You could test this in code, to see for yourself:

    self.display.text = @"1.0";
    self.firstNumber = [self.display.text doubleValue];
    self.display.text = @"2.0";
    NSLog(@"firstNumber is: %g", self.firstNumber);
    

    You’ll see that even after self.display.text changes, self.firstNumber does not.

    So, your problem is somewhere else. Perhaps your -pressedAction: method is being called more often than you think it is? In iOS, it’s possible that a button can send more than one action when it is pressed — perhaps you copied-and-pasted a button that was sending -pressedAction: and then you added another action to that button afterwards.

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

Sidebar

Related Questions

the question explains it all. For instance, if I have a NSDictionary like this
Question: I have to create a tablet application. In this i want to make
I know that this question seems illogical, but I have to try, and I
I'm a Ruby newbie. Have a very basic question about static and instance variables.
I have read from the question How to gain access to a ServletContext instance
I have a noob-question, that might be similar to Dynamically create multiple instances of
No doubt elements of this question have been asked before, but I'm having trouble
I know variants of this question have been asked before (even by me), but
Hi there I have a bit of a noob question about creating unique variable
I have only a vague idea on phrasing this, so question as needed: I

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.