objective c - Do declared properties require a corresponding instance variable? -


Does it require the corresponding variable variable to declare properties in Object-C 2.0? For example, I used to do something like this:

MyObject.h

@Interface MyObject: NSObject { NSString * name; } @ Property (nanatomic, retten) nssting * name; @end

MyObject.m

  @implementation @ synthesize name; @end  

However, if I have done this instead:

MyObject.h

  @ Interface MyObject: NSObject {} @property (nonatomic, retain) NSString * name; @end  

Is it still valid? And is it different from my previous example?

If you are using the modern purpose - runtime (this is either iOS 3.x or More, or 64-bit snow leopard or more) then you need not to define the ivores in such cases for your properties.

When you do the @ synthesis property, Ivar will also be synthesized for you. It is around the "delicate-ivore" scenario that you can read more about it at


Comments