Single blog// see post details
Design Patterns: KVO
KVO can be a very powerful and useful design pattern. Here, we’ll discuss how to make it work.
First of all, you’ll want to create an observer to listen for any key posts. Here’s how you add an observer:
[[NSNotificationCenter defaultCenter] addObserver:self
Let’s go over this method.
Now that we’ve added an observer, we want to post the notification. Here’s the code to do that:
[[NSNotificationCenter defaultCenter] postNotificationName:keyValue object:self];
Finally, we can’t forget to remove the observer in dealloc. Here’s the code to remove it:
[[NSNotificationCenter defaultCenter] removeObserver:keyValue];
That’s all there is to it. It’s pretty simple once all is said and done.