合成属性在类接口中是否需要指针?

时间:2012-07-02 17:40:22

标签: objective-c pointers

  

可能重复:
  Is there any reason to declare ivars if you're using properties exclusively in Objective-C?

这堂课:

@interface MyClass
{
    Something* pointer;
}
@property (nonatomic, retain) Something* pointer;
@end

@implementation MyClass
@synthesize pointer
@end

显然与以下相同:

@interface MyClass
@property (nonatomic, retain) Something* pointer;
@end

@implementation MyClass
@synthesize pointer
@end

创建合成属性时,是否还需要在其类接口中指向它?我注意到我的程序显然运行相同,无论我是否有指针。是否声明指针是否更好?

1 个答案:

答案 0 :(得分:1)

你曾经,但你不再了。编译器现在自动填充它,所以您只需要声明@property@synthesize