NarbehM
NarbehM

Reputation: 345

properties synthesize and iVars

Disclaimer: I'm pretty new to Objective-C

I have a couple of questions related to @property and @synthesize.

Let's say I have property

@property (strong, nonatomic) NSString *name;

1- I know that on Xcode 4.4+ you can skip doing @synthesize for the properties as they are automatically done. So I assume that the iVar generated should be the same as the name of the property right? In general, If I do @synthesize name; the iVar would be the same as the name of the property?

2- I know that @synthesize name = _name; is used when I have manually declared a private variable with the name of _name and I want to make the compiler use it as my property's iVar. I need to know, what happens if I do @synthesize name = _name; WITHOUT actually having a private variable declared.

Thank you in advance.

Upvotes: 0

Views: 184

Answers (1)

Wolfgang Schreurs
Wolfgang Schreurs

Reputation: 11834

  1. If I'm not mistaken, the default iVars that are generated start with an underscore. I.e.: the default iVar for the property name would be _name.
  2. The iVar _name will be generated for the property name. No need to manually create any iVar when @synthesize does the job for you, though there won't be any issues if you do want to manually add them.

Upvotes: 1

Related Questions