why isn’t my original variable changed when I pass by reference a CoreData managed Object variable?
So I have in my iPhone application, a coredata managed object called Config. One of the variables in the XCode 4 produced *.h and *.m files is “@dynamic height;” (I point this out because I wonder if it’s related to this). When accessing this variable in code it is an NSNumber.
So when I setup a new data selection view/controller I set a variable in this controller to be equal to height, so that when I change it in the next view & come back, it should be changed in the 1st view (pass by ref concept).
Only problem is that it doesn’t seem to change the value?
Some code extracts:
@interface Config : NSManagedObject {
@private
}
@property (nonatomic, retain) NSNumber * height;
@end
@implementation Config
@dynamic height;
@end
Calling the 2nd view
// Prepare
SelectorController *sc = [[SelectorController alloc] initWithStyle:UITableViewStyleGrouped];
sc.returnValue = self.config.height;
// Show New Window
[self.navigationController pushViewController:sc animated:YES];
[sc release];
Section Controller
@interface SelectorController : UITableViewController {
NSNumber *_returnValue;
}
@property (nonatomic, retain) NSNumber *returnValue;
@end
NSNumberis immutable, that is, you can’t change its value after it’s created. When you assign a new value to anNSNumberproperty, it’s a completely different object and the original object doesn’t change at all.