可能重複:
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
WHE你創建一個綜合屬性,你還需要一個指向它的類接口的指針嗎?我注意到我的程序顯然運行相同,不管我是否有指針。指針是否被聲明更好?
[有沒有任何理由聲明ivars,如果你只在Objective-C中使用屬性?](http://stackoverflow.com/q/4903651/),[屬性和實例變量](http :[//stackoverflow.com/q/3074248/),[我們應該聲明ivars還是讓編譯器去做?](http://stackoverflow.com/q/8047128/),[Property declaration and automatic backing storage]( http://stackoverflow.com/q/3238009/),[我們需要聲明ivars嗎?](http://stackoverflow.com/q/5864221/) –
可能[其他](http:// stackoverflow。 COM /搜索q =聲明+的ivars +爲+屬性+%5Bobjc%5D&提交=搜索)。 –