They can have the same name, although they don't have to. Indeed, it's not required for the externally-visible property to correspond exactly to a single instance variable at all. Such a correspondence is expected if you're going to @synthesize
the accessor methods, but there are quite legitimate reasons for creating the methods manually and making them do something other than just getting/setting a matching ivar.
Instance variables are normally not accessible from the outside world, so all external access has to be via the property methods. (It is possible to declare ivars @public
, but this is rarely a good idea.)
From within the object, whether you access as properties or instance variables depends on what the properties actually are and what you're doing with them.
For simple synthesized properties it is common to use the accessors (either explicitly using [self setXxx]
or using the dot notation as self.xxx
) except within dealloc
(and possibly init
, depending on who you ask).
In more complex cases, you really have to think about what it is you are trying to achieve. But if you've gone to the trouble of making them properties you probably want whatever functionality is encapsulated in the accessor methods to be called most of the time.
At any rate, read the properties documentation to get a better understanding of what's going on.