0

Possible Duplicate:
Is there any reason to declare ivars if you're using properties exclusively in Objective-C?

This class:

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

@implementation MyClass
@synthesize pointer
@end

Apparently runs the same as:

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

@implementation MyClass
@synthesize pointer
@end

When you create a synthesized property, do you also need a pointer to it in its class interface? I noticed that my program apparently runs the same whether I have the pointer or not. Is it better to have the pointer declared or not?

Community
  • 1
  • 1
JoJo
  • 19,587
  • 34
  • 106
  • 162
  • possible duplicate of [Is there any reason to declare ivars if you're using properties exclusively in Objective-C?](http://stackoverflow.com/q/4903651/), [Properties and Instance Variables](http://stackoverflow.com/q/3074248/), [Should we declare ivars or let the compiler do it?](http://stackoverflow.com/q/8047128/), [Property declaration and automatic backing storage](http://stackoverflow.com/q/3238009/), [Do we need to declare ivars?](http://stackoverflow.com/q/5864221/) – jscs Jul 02 '12 at 17:41
  • Possibly [among others](http://stackoverflow.com/search?q=declare+ivars+for+properties+%5Bobjc%5D&submit=search). – jscs Jul 02 '12 at 17:47

1 Answers1

1

You used to, but you don't anymore. The compiler fills it in automatically for you now, so all you need is to declare the @property and @synthesize it.

Dima
  • 23,484
  • 6
  • 56
  • 83
  • It is a property of the modern runtime, which has been used in all versions of iOS and since OSX 10.5 on Mac. Documentation [here](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtVersionsPlatforms.html#//apple_ref/doc/uid/TP40008048-CH106) – Dima Jul 02 '12 at 18:18