0

I'm learning objective-c and there is something I couldn't find an answer to.

I have declared a property in the public interface of a class. In that class I can access the ivar directly by using underscore, without synthesizing the property.

For example:
// Class.h @property (nonatomic, strong) NSString *someString; // Class.m _someString = something;

But if I subclass that class, I can access the setter and getter without any extra code, but I can't access the ivar directly, unless I explicitly synthesize the property, which was not necessary step in the superclass.

I know for a fact that it does create ivars specific for the subclass, because I have 2 subclasses of the same superclass, and each have their own values for the superclass's properties. I just don't understand why I need to explicitly synthesize the subclass if I want to access the ivars directly.

It isn't really a problem, but more of a curiosity.

AMI289
  • 1,098
  • 9
  • 10
  • try `self.someString` instead of `_someString` – sage444 Sep 30 '14 at 09:27
  • Thank for your reply. your suggestion is accessing the getter method. I'm asking about accessing the ivar directly. – AMI289 Sep 30 '14 at 10:03
  • Possible duplicate of [override property from superclass in subclass](https://stackoverflow.com/questions/17127056/override-property-from-superclass-in-subclass) – malhal Mar 06 '18 at 15:19

0 Answers0