iphone - When declare a property(retain) in objective c, what's the default implementation of set/get method -


i newer objective c. have read memory management document on apple's "memory management rules". still not clear how manage reference property.

what's default implementation of set/get access methods property declared "retain" annotation?

this assuming, please give comments. thanks.

@interface subclass : nsobject { nsstring * _name; } ... ... @property (nonatomic, retain) nsstring * name; ... ... @end  -(nsstring *) setname {    return _name; }  -(void) setname: (nsstring *) pname{     // correct version of default set method retain     if( _name != pname ) {         [_name release];         _name = [pname retain];     }  } 

so dealloc method, ok?

- (void)dealloc {     self.name = nil; // or [_name release], _name = nil;  } 

as matteo alessani says, can synthesize property default implementations.

for reference, what's generated (i got reading objective-c declared properties , piecing information together):

- (nsstring *)name {     return _name; }  - (void)setname:(nsstring *)aname {     if (_name != aname) {         [_name release];         _name = [aname retain];     } } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -