Objective-Cでは、次のことを行うのがベストプラクティスですか。
.hでボタンなどのオブジェクトを宣言してから、.mで合成します
.h @interface SomeViewController : UIViewController @property (strong, nonatomic) UIButton *someButton; @end .m @implementation SomeViewController @synthesize someButton = _someButton; @end
または、.mでそれらをivarとして宣言します
@interface SomeViewController () @property (strong, nonatomic) UIButton *someButton; @end
多くのAppleコード、特にBreadcrumbsサンプルコードでは、それらのプロパティの多くがインターフェイスで宣言されていることに気付きました。2つの間に違いはありますか?@interface
また、プロパティがで宣言されている場合、プロパティはアンダースコアプレフィックスを使用して自動的に合成されるため、someButton = _someButton
合成が役に立たないことに気付きました。