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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:49:24+00:00 2026-05-22T01:49:24+00:00

So I have this class: @interface AmountViewController : UITableViewController <UITableViewDelegate, UITextFieldDelegate>{ NSManagedObjectContext *managedObjectContext; NSManagedObject

  • 0

So I have this class:

@interface AmountViewController : UITableViewController <UITableViewDelegate, UITextFieldDelegate>{

NSManagedObjectContext *managedObjectContext;
NSManagedObject *selectedObject;

NSDecimalNumber *amount;
NSDecimalNumber *accountBalance;

NSInteger textFieldRow;

}
- (void)textFieldDone:(id)sender;
- (NSDecimalNumber *)absoluteValue:(NSDecimalNumber *)number;

@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain) NSManagedObject *selectedObject;
@property (nonatomic, retain) NSDecimalNumber *amount;
@property (nonatomic, retain) NSDecimalNumber *accountBalance;
@property NSInteger textFieldRow;

@end

Now in my implementation

- (void)viewWillDisappear:(BOOL)animated {
NSLog(@"Select Object Amount Value: %@", [selectedObject valueForKey:@"amount"]);
if (amount != nil) //amount is out of scope, has something to do with retain, but accountBalance is in scope. ???
{
    NSLog(@"Textfield Amount: %@", amount);
    //TODO: save changes to amount
    //[selectedObject setValue:amount forKey:@"amount"];

    NSError *error = nil;
    if (managedObjectContext != nil) {
        if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        } 
    }

    NSLog(@"Select Object Amount Value (after save): %@", [selectedObject valueForKey:@"amount"]);
}
[super viewWillDisappear:animated];
}

For some reason, the amount object is ‘out of scope’ only if i modify its value before reaching the viewWillDisappear method. So for instance, I load this view and press back, everything is good. But if I change the amount value then press back, the debugger shows that the amount is out of scope. My thinking here is that the object is getting released prior to reaching the viewWillDisappear method, but I’m not sure what exactly to do. I tried other variations of (atomic/nonatomoic, retain/assign/copy) but I’m not sure I really understand all that even after reading about them. :/

Also, the selectedObject, accountBalance and other objects are still in scope even though they have the same property attributes. Any help is appreciated. Thanks. Let me know if I can provide more info for you.

  • 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-22T01:49:25+00:00Added an answer on May 22, 2026 at 1:49 am

    You’re right. It could be that amount is getting released when you change its value. When you’re setting the new value for amount, its previous owner may be releasing it. But, if you are setting the new value directly to the instance variable, you are not retaining it.

    To actually use the setters and getters that are synthesized according to your property rules (i.e. retain, etc.), you must access them as follows:

    self.amount
    self.amount = newValue;
    

    You are bypassing the synthesized setters and getters if you access the instance variables directly, as follows:

    amount
    amount = newValue;
    

    If you always use self.amount rather than amount to refer to your instance variable, you may save yourself a lot of trouble.

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

Sidebar

Related Questions

Let's say I have a class that implements the IDisposable interface. Something like this:
I have this class/interface definitions in C# public class FooBase { ... protected bool
I have this simple interface/class: public abstract class Message {} public class Message1 extends
I have this class loader.h #import <Foundation/Foundation.h> @class Reachability; @interface loader : NSObject {
This is a little contrived, but say I have a class interface like this:
I want to have an argument of type this class in an interface's method
I have a class like this: @interface MyCollection : NSObject { NSMutableDictionary *data; }
I have this class: @interface G2Matrix : NSObject ... - (id) initWithArray:(float *)val; ...
I have this class hierarchy: public interface ISR { } public interface ICU {
I have this interface and a class implementing it: interface Scraper { string DateToUrl(DateTime

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.