Home > DeveloperSection > Interviews > Why do we need to use @Synthesize?

Posted on    July-14-2015 7:49 AM

 iPhone iPhone  Ios  Objective C 
Ratings:
 1 Answer(s)
  376  View(s)
Rate this:

Tarun Kumar

Total Post:107

Points:535
Posted on    July-14-2015 7:49 AM

when you create a property...

@property NSString *name;

Xcode will auto synthesise an iVar as if you had written...

@synthesize name = _name;

This means you can access the property with...

self.name;
// or
_name;

Either will work but only self.name actually uses the accessor methods.

There is only one time that auto synthesise does not work.

If you overwrite but the setter AND the getter method then you will need to synthesise the iVar.

You are fine if you just override the setter or if you just override the getter. But if you do both then the compiler won't understand it and you will need to synthesise it manually.

As a rule of thumb though.

Don't make iVars. Just use the property. Don't synthesise it.


Modified On Jul-14-2015 07:53:35 AM

Don't want to miss updates? Please click the below button!

Follow MindStick