NSNotification VS KVO

I feel like I don’t quite understand the difference between KVO and NSNotification ... It seems they are so similar ... Could you give an example when it is best to use one method and the other?

I'm not talking about Bind and IB, but I mean adding Observer programmatically to my code with NSNotificationCenter or KVO

[self.preferenceController addObserver:self forKeyPath:@"color" options:NSKeyValueObservingOptionOld context:@"Color-change" ]; 
+6
source share
1 answer

KVO only works with values, NSNotification can be used to change values, but it can be used for anything and can carry a much larger payload.

For example, you could publish NSNotification whenever the file completed the download, and user information might contain the time taken to load the bytes and the path to the file system where the file was saved.

+6
source

Source: https://habr.com/ru/post/892833/


All Articles