I realize that there are already many property vs. ivar questions on here, but after doing a lot of research I can't seem to find a clear answer.
I understand that when you declare a property like the following, that the compiler automatically synthesizes the backing ivar and the two accessor methods for you:
@property NSString *myString;
What still confuses me is, is myString
an actual instance variable? The reason I ask this is because you can never access it like this:
NSLog(@"Value of myString is: %@", myString);
You either have to use the backing ivar _myString
, or one of the getter methods like [self myString]
or self.myString
. So I'm confused because normally you could just use the variable name plain and simple.
To top it all off, I've been told that you should not refer to myString
as a property, and that the word property should only be used to refer to the two accessor methods that are synthesized for you by the compiler when you use the @property
directive.
Would it really be wrong for you to say "I have a property called myString" , and if that is wrong then what would be the correct way to say it?
Any help clearing this up would be greatly appreciated. I've been struggling with solidifying the idea of properties and ivars being different things all day now.