WHY DO WE NEED TO USE @SYNTHESIZE?

Tarun Kumar

Total Post:107

Points:535
Posted by  Tarun Kumar
 574  View(s)
Ratings:
Rate this:
  1. Tarun Kumar

    Post:107

    Points:535
    Why do we need to use @Synthesize?

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!