ios界面iVar vs属性 [英] ios interface iVar vs Property
问题描述
在.h文件中,两者之间有什么区别
In an .h file, what is the difference between:
@interface ViewController : UIViewController
@property (strong, nonatomic) UIView* myView;
还有
@interface ViewController : UIViewController{
UIView* myView;
}
推荐答案
主要区别是@property对其他对象可见,并且可以使用您的类的实例对其进行访问.
The main difference is that a @property is visible to other objects, and can be accessed by these using an instance of your class.
您可以在实现文件中使用@synthesize来自动实现实现中的degetter setter函数定义.
You can use @synthesize in your implementation file to automate definition de getter setter functions in your implementation.
更新(遵循@ Graham Lee 的建议)
根据实例变量(@protected/@private/@public)的可见性说明符,可以在实现文件,子类或其他类中使用ivar.隐式值是@protected,因此在您的示例中,实现文件和子类将可见该值.
According to the visibility specifier for your instance variable (@protected / @private / @public) , the ivar can be used in your implementation file, subclasses or other classes. The implicit value is @protected, so in your example it will be visible to your implementation file and subclasses.
这篇关于ios界面iVar vs属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!