What is the difference between accessing an instance variable using
self.mName = name;
against
mName = name;
The first is property access syntax. It is converted to an object access message (in this case, self ). That is, this statement implicitly translates this message expression expression:
[self setMName:name]
(Incorrect accessory names, such as why โmNameโ is a bad name for a property. The property declaration syntax is used to do this, letting you name the property name โnameโ and your instance variable โmNameโ and map one to the other.)
The second example directly accesses the message of the instance variable without access.
Which is not @property and is not @ sythenize'd.
Say it's all the same ...
If a property with the name " mName " is not declared for the class, you cannot use the property access syntax to access the property using this name in an instance of this class.
And it doesnโt matter if you synthesize accessors, manually translate them into a superclass with @dynamic or define them yourself. The way the object will respond to the access message, but the access message that the compiler generates, will not differ (since access to properties can just as easily happen from outside the class as from the inside).
Let's say iVar was not an IBOutlet:
It does not matter. IBOutlet means just anything for IB. Everything else is all the same.
In fact, IBOutlet is currently just a macro that expands to zero. After your code receives preprocessing, the word "IBOutlet" no longer exists, so the compiler never sees it. This is slightly different from anything other than IB: Nothing.
Edit in response to editing a question
I said that mName is bad as a property name, due to the access names that follow from it. The instance variable name is a separate issue, especially because the property and ivar must not have the same name.
For a variable, whether it be an instance variable or a local variable, choosing name or m_name or mName is purely a style choice.
someMethod: usually an accessory, setX: . Inside this method, self.x = x , which is [self setX:x] , causes infinite recursion. So do not do this.
When someMethod: not an accessory (either init or dealloc ), using a property is just fine and usually preferable. However, in this case, you are unlikely to pass one of your arguments the same name as the instance variable. When such a case may occur, specify the local variable more specifically, since its purpose is more specific. This is also a style issue.
When it is an accessor, I find the local variable newX by naming the instance variable the same as the property, x . This is my personal style; as I said, naming the property x , ivar mX , and the local variable x is fine too (except for the excessive brevity of this example).