Losing data variable on changing view in iOS

I have a variable in my viewcontroller.h declared as

@property (nonatomic) uint size;

On the viewcontrooler.m, I set a value to this variable when a button is pressed.

The problem is, when I change a view and return back, the value of my variable is lost.

What can i do do solve that? I don't need to declare it as a global variable, because I just use it in the ViewController.m.


What I would do is on viewWillDissapear I would save the value with

[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%i", size] forKey:@"mySize"];

and I would just retrieve this value on viewWillAppear with

size = [[[NSUserDefaults standardUserDefaults] objectForKey:@"mySize"] intValue];

Then if you wants to delete the value from app just use:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"mySize"];

One thing I would also try is declaring the property without non atomic (maybe you will retain the value between screens because of that!):

@property uint size;

Need Your Help

Editing text in a document

python python-3.x

I'm trying to add XML tags around a text document. Here is my code