views:

47

answers:

1

I need to create two instances of two classes inside a view controller that stay alive for the entire time that view is open.

Inside theese one of theese classes I need to create a NSString and a NSDate that stays alive for the entire time the class is alive.

How do I do this?

+2  A: 

define 2 variables in the class:

NSString* s;
NSDate* date;

Too keep the variables alive while the view is visible:

in viewDidAppear:

s = [@"A string" retain];
d = [[NSDate date] retain];

in viewDidDissapear:

[s release];
[d release];

if you need it for the entire time the class is alive move the code to the init and dealloc methods.

skorulis
for some reason this throws an NSException when I do this in my own class.
pki