You will receive a KVO notification only when accessing an instance variable through a property. Direct setup of an instance variable will not trigger a KVO notification.
In the first case, you set the name
self.name = @"b";
In fact, this will call the setName: property setting method, which internally sends KVO didChangeValueForKey notifications. In fact, notifications are called by calling the setter method.
In the second case
_name = @"b";
You directly set the instance variable without the set setter method. Therefore, the KVO notification will not start.
If you want, you can run the notification yourself
[self willChangeValueForKey:@"name"]; _name = @"b"; [self didChangeValueForKey:@"name"];
But I do not think it requires, set the variable using the property. This will do everything for you.
Read more about KVO Notice
source share