In Objective-C, is it best practice to:
Declare objects such as buttons in the .h and then synthesize in the .m
.h @interface SomeViewController : UIViewController @property (strong, nonatomic) UIButton *someButton; @end .m @implementation SomeViewController @synthesize someButton = _someButton; @end
or declare them as ivars in the .m
@interface SomeViewController () @property (strong, nonatomic) UIButton *someButton; @end
I notice that in a lot of Apple code, specifically their Breadcrumbs sample code, many of their properties are declared in the interface. Is there a difference between the two? I also noticed that when properties are declared in the @interface
, they are automatically synthesized with an underscore prefix, making the someButton = _someButton
synthesis useless.