@property和@synthesize有什么区别?

Tha*_*nks 3 cocoa-touch properties objective-c uikit

就像我理解的那样,@synthesize实际上是生成Getters和Setter.但是什么是@property呢?它只是为那个很酷的@synthesize魔术功能设置参数吗?

pgb*_*pgb 9

@property将名称声明为属性.这意味着,它可以通过点语法(object.value)访问.

@synthetize可以看作是一个宏,它创建了getter和setter方法.知道您可以覆盖这些方法很有用,即使您键入了这些方法也是如此@synthetize.


oxi*_*gen 8

你在头文件中写@property

@property float value;
Run Code Online (Sandbox Code Playgroud)

相当于:

- (float)value; 
- (void)setValue:(float)newValue; 
Run Code Online (Sandbox Code Playgroud)

它获取OTHER类的信息,您的类具有此方法

@synthesize phisicaly在类实现中创建这些方法