self.view and view / _view are not the same thing. Depending on how you create the instance variables, view or _view refers to the actual instance variable of the object. It is wrong to access this directly, and you should only do this in init , dealloc or in accessories. Elsewhere you should use self.view .
self.view exactly the same as [self view] , which passes the message "view" to the object "self", and returns the result. By default, when an object receives a message, it executes a method with that name, and the default implementation of view returns the value of the corresponding instance variable (either view or _view ).
In older versions of Xcode, @synthesize view will create an instance variable called view . In recent versions of Xcode, declaring a view property will automatically create an instance variable called _view in many cases, even without @synthesize . This change makes notification easier when you contact ivar directly.
In short:
- with the exception of
init , dealloc and view accessories (if you are their manufacturers), always use self.view . - In these methods, you should call it
_view . - If you are writing the latest Xcode, do not include
@synthesize at all. If you are writing a bit outdated Xcode, use @synthesize view=_view; self.view does not mean "value of an instance variable". This means the "result" of the message, which is usually implemented as returning an instance variable.
source share