Difference between self.variable and _variable,about KVO
You will get KVO notification only when you are accessing the instance variable through a property. Direct setting of instance variable will not invoke KVO notification.
Here the first case, you are setting the name by
self.name = @"b";
In fact this will call the property setter method setName:
which internally sends the KVO notifications didChangeValueForKey
. Actually the notifications are fired by the calling of setter method..
In the second case
_name = @"b";
You are directly setting the instance variable, without a property setter method. So the KVO notification will not be fired.
If you want you can fire the notification by yourself
[self willChangeValueForKey:@"name"];
_name = @"b";
[self didChangeValueForKey:@"name"];
But i dont think it requires, set the variable using the property. That will do everything for you.
Read more about KVO notification