Why is my object out of scope in viewWillDisappear if i change the object's value?
<p>So I have this class:</p>

<pre><code>@interface AmountViewController : UITableViewController &lt;UITableViewDelegate, UITextFieldDelegate&gt;{

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
</code></pre>

<p>Now in my implementation</p>

<pre><code>- (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] &amp;&amp; ![managedObjectContext save:&amp;error]) {
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        } 
    }

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

<p>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. :/ </p>

<p>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.</p>
