KVO vs NSNotification vs protocol/delegates?

Ankit Srivastava picture Ankit Srivastava · Oct 23, 2011 · Viewed 21.4k times · Source

I have some idea of which to use when but the exact usage is still not clear to me. Can someone explain with example?

Answer

deanWombourne picture deanWombourne · Oct 23, 2011

Use a delegate if you want to talk to only one object. For example, a tableView has a delegate - only one object should be responsible for dealing with it.

Use notifications if you want to tell everyone that something has happened. For example in low memory situations a notification is sent telling your app that there has been a memory warning. Because lots of objects in your app might want to lower their memory usage it's a notification.

I don't think KVO is a good idea at all and try not to use it but, if you want to find out if a property has changed you can listen for changes.

Hope that helps.

PS This sums up why I think KVO is broken