should variable be retained or not? iphone-sdk
- by psebos
Hi, in the following piece of code I got from a book.
The NSString *pPath which is defined in the class as an instance variable.
@interface MainViewController : UIViewController {
NSString *pPath;
}
In the implementation after being set it is being retained. I assume that with the assignment the object is automatically retained (because it is an NSString) and there is no need to additionally retain it.
- (void) initPrefsFilePath {
NSString *documentsDirectory =
[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
pPath = [documentsDirectory stringByAppendingPathComponent:
@"flippingprefs.plist"];
[pPath retain];
}