You describe the BAD_ACCESS problem in some of your other comments. Something is happening here. In ARC, your Ivars are strong, unless otherwise indicated (and in non-ARC they are not going to be exempted from your name).
For example, this ARC code works fine, without BAD_ACCESS, when you post other answers in your comments:
@interface ArcTestViewController () { NSMutableArray *_someArray; } @end @implementation ArcTestViewController - (void)dealloc { _someArray = nil; } - (void)viewDidLoad { [super viewDidLoad]; _someArray = [[NSMutableArray alloc] initWithObjects:@"Mo", @"Larry", @"Curly", nil]; } - (IBAction)checkIvarTouchUpInside:(id)sender { NSLog(@"%s _someArray = %@", __FUNCTION__, _someArray); } @end
You may need to show us your example when you receive your BAD_ACCESS, because it must be something else.
In response to the question “property” or “ivar”, although I sympathize with the argument “always use properties”, I personally use properties for something, for which I need to provide external accessors, otherwise I use personal ivars (and not in .h, but rather in the private interface in the .m file). This makes my public interfaces in my .h files really clean and clear when I return to them after a few months. If you take the “always use properties” approach, I would only say that your public declaration of these properties should be as restrictive as possible (make the property private, if possible, make the public declaration of readonly property if you do not need to provide readwrite access and etc.).
By the way, Naming the properties and data types of the Cocoa Coding Guide is a good reference to best practices.
Rob
source share