Property attribute “retain” doesn't seem to be working?


Property attribute “retain” doesn't seem to be working?



I've implemented a bit of code from one of the many Apple code examples, but I'm having a bit of trouble, because the retain attribute of one of the properties doesn't appear to be working. Here's the property declaration:

@property (nonatomic, retain) EditingViewController *editingViewController; 

And here's the code:

- (EditingViewController *)editingViewController {     // Instantiate the editing view controller if necessary.     if (editingViewController == nil) {         EditingViewController *aController = [[EditingViewController alloc] init];         editingViewController = aController;         [aController release];     }     return editingViewController; } 

I understand that (retain) is supposed to cause the retain count to increase by 1 on assignment; however, the code fails unless I do send [aController retain] myself, or don't send [aController release]. What am I missing here?


UICachedDeviceWhiteColor and NSAutoRelease for table cell mem leaks

1:

Can I develop an iPhone app using java?
When you reference editingViewController, it is equivalent to self->editingViewController, i.e. Lock orientation UIWebView on iPhonean access to an ivar.. How to ALTER sqlite column (iPhone)? If you want to use a receive ter or setter, you need to use self.editingViewController, or equivalently [self setEditingViewController:aController].. How to escape characters in href=mailto (iPhone) This is why I prefer to use an ivar with a different name to the property, for example:. iPhone SDK: UIWebView
EditingViewController* i_editingViewController;  @property (nonatomic, retain) EditingViewController *editingViewController;  @synthesize editingViewController = i_editingViewController; 
Then you must write your lazy receive ter as:. Focus OnLoad=“document.form_id.form_field_id.focus();” on the iPhone
- (EditingViewController *)editingViewController {     // Instantiate the editing view controller if necessary. Getting access to touchesBegan/Moved/Ended to a UITableViewCell    if (i_editingViewController == nil) {         i_editingViewController = [[EditingViewController alloc] init];     }     return i_editingViewController; } 
or.
- (EditingViewController *)editingViewController {     // Instantiate the editing view controller if necessary.     if (i_editingViewController == nil) {         EditingViewController *aController = [[EditingViewController alloc] init];         self.editingViewController = aController;         [aController release];     }     return i_editingViewController; } 
I would probably use the former method (not invoking the setter) for the reason this the value of editingViewController (as seen by any observer) has not really changed, although either way should job fine and the different name (for ivar and property) guidance avoid the confusion or accidental misused. It is also a mild encouragement to use the property (since it avoids the slightly ugly prefix).. Note this Apple reserves the _ prefix, and this setters and receive ters should not be used in the init/dealloc routines..

2:

You have to write self.editingViewController in rule to use the property. Just "editingViewController" is a direct access to the Class member variable, whereas self.editingViewController is equivalent to [self setEditingViewController:...] and will did the appropriate retain/release job..


96 out of 100 based on 71 user ratings 486 reviews