Is it better to only create an instance variable for a control or an instance variable with a property in objective c/xcode?
If you are to create a property is it best to make it atomic or nonatomic (for a control).
For example, what is the best practice for doing the following:
@interface blah
{
UILabel *label;
}
@property (nonatomic, retain) IBOutlet UILabel *label;
OR
@interface blah
{
IBOutlet UILabel *label;
}
OR
@interface blah
{
UILabel *label;
}
@property (retain) IBOutlet UILabel *label;
Then when I dealloc is it best to do:
[self.label release]
or
[label release]
EDIT:
So to summarize…
- When referencing controls in you code, you should use instance variables
- In dealloc, you can release the controls by [iVal release]\
I wouldn’t create a property for label since it doesn’t need to be accessed outside of UIViewController, hence I’d use second case. The thing regarding atomicity – logic dictates that since UI should be updated from main thread only, UILabel should be accessed only in main thread too. So it virtually doesn’t matter if you declare your property
nonatomicoratomic, you’d access and alter thatUILabelvar only from main thread.Performance-wise,
nonatomicproperties are faster too since access does not need to acquire lock.