should variable be retained or not? iphone-sdk

Posted by psebos on Stack Overflow See other posts from Stack Overflow or by psebos
Published on 2010-03-19T08:50:09Z Indexed on 2010/03/19 8:51 UTC
Read the original article Hit count: 222

Filed under:
|
|

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]; 
} 

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk