在.h文件中,有什么区别:
@interface ViewController : UIViewController
@property (strong, nonatomic) UIView* myView;
Run Code Online (Sandbox Code Playgroud)
和
@interface ViewController : UIViewController{
UIView* myView;
}
Run Code Online (Sandbox Code Playgroud)
主要区别在于@property对其他对象是可见的,并且可以使用您的类的实例来访问它们.
您可以在实现文件中使用@synthesize来自动执行实现中的定义de getter setter函数.
更新(遵循@ Graham Lee的建议)
根据实例变量(@protected/@private/@public)的可见性说明符,可以在实现文件,子类或其他类中使用ivar.隐式值是@protected,因此在您的示例中,它将对您的实现文件和子类可见.
| 归档时间: |
|
| 查看次数: |
6288 次 |
| 最近记录: |