Reputation: 1363
I need a way to create variables that are accessible for the entire time my custom class is initiated to when I call the release function. I need to retain a NSDate and a NSString.
Upvotes: 0
Views: 76
Reputation: 723428
Give your custom class retain properties for each variable in its header file:
@property (nonatomic, retain) NSDate *myDate;
@property (nonatomic, retain) NSString *myString;
Be sure to create proper setters and getters, or use @synthesize
, in its implementation file:
@synthesize myDate, myString;
Upvotes: 0
Reputation: 85522
Autorelease just fires a -release message at a later time. If you want your variables to stick around, -retain them when they're assigned. Even if they're autoreleased, your retain will increment the retainCount, so they will not be dealloced. Just be sure to -release them in YOUR dealloc.
Upvotes: 1
Reputation: 8990
Do [myObject retain]
or @property(nonatomic, retain) MyClass *myObject;
Upvotes: 1