-1

Possible Duplicate:
@property @synthesize

Hi i found in so many apps after creating the @property we have to declare @synthsize also but i would like to know the difference between

NSArray *_failedBankInfos;

@property (nonatomic, retain) NSArray *failedBankInfos;
@synthesize failedBankInfos = _failedBankInfos;

and

@property (nonatomic, retain) NSArray *_failedBankInfos;
@synthesize _failedBankInfos;

can anyone explain this please.

Community
  • 1
  • 1
GNJ
  • 1
  • 2
  • 2
    Please do a search there are lots of questions regarding this topic. http://stackoverflow.com/questions/2032826/property-synthesize – iNoob Jun 21 '12 at 04:57

1 Answers1

3

@synthesize will map the property with the declaration of the iVar i.e. will create the getter and setter methods without needing the developer to implement the accessor methods explicitly and the memory management in them(as per the parameters inside the @property eg: retain, copy.). So, when we use the *_iVar(which is supposed to be a private iVar as per the naming conventions) and we want to have the accessor methods look like the ones without the "_" eg: [aClass getIVar] and not [aClass get_iVar] we map the _iVar with the @synthesize iVar=_iVar to the property @property(retain/copy/assign,atomic/nonatomic) NSObject *iVar;

PS: Also refer the Automatic Reference Count in iOS>=5.0 at Ray's

Ishank
  • 2,860
  • 32
  • 43
  • hi ishak thanks for your reply.Here can please explain when we have to use _ and when no need to use that. – GNJ Jun 21 '12 at 06:01
  • hey man, u r welcome! Its just a naming convention that indicates that the iVar is supposed to be private i.e not visible to other classes(called Encapsulation in OOP) so, its good if we declare the corresponding @property in the .m file of the Class rather than the .h file such that the class itself can make use of the property while others can't. – Ishank Jun 21 '12 at 06:13