我已经花了几天的时间学习Objective-C并且有几个关于@property
的问题。我有C#经验,了解需要指针,初始化等为什么我可以使用内联变量来声明@property?
因此,作为一个例子:
@interface MyClass : NSObject
{
IBOutlet UIImageView *image;
}
@property (retain, nonatomic) UIImageView *image
@end
@implementation MyClass
@synthesise image
@end
我明白@synthesise
被用于创建@property
。但是,我有几个问题,只是帮我收拾东西:
- 是否
@property
重复或取代我的原始定义,或者它仅仅是建立在原有的mutibility和原子? - 是否
@synthesise
删除我的需要使用image = [[UIImageView alloc] init]
? - 如果我没有提供
@property
,仍然继续创建并手动销毁我的变量,这是否有所作为?
最终,两者之间的区别在于,@property为您提供了关于内存管理和多线程的更多灵活性,正常的默认值给您提供了灵活性。
@prototype不是Objective-C关键字。你的意思是@property? – zpasternack 2012-04-13 07:59:59
你的意思是@property,right – willc2 2012-04-13 08:00:14
对不起,在手机上打字。很快就会改变它。感谢您的发现。 – 2012-04-13 08:10:27