Should I declare variables in interface or using property in objective-c arc?

前端 未结 2 1978
无人共我
无人共我 2020-11-28 05:04

approach 1:

@interface MyController : UIViewController {
    UILabel *myText;
}

@property (nonatomic, strong) UILabel *myText;

approach 2:

2条回答
  •  感情败类
    2020-11-28 05:09

    You may also want to use @synthesize if you like a nice table of contents of your @synthesized properties that you can refer to and comment for clarity and organization.

    Also, an @synthesize allows you to set a breakpoint on the property and trap when its value is changed.

    When the compiler does everything for you, you end up being distanced from what is really happening and ignorant to it. However, not having to type out everything yourself all the time is also nice.

提交回复
热议问题