Difference between delegate and notification.

Short Answer: You can think of delegates like a telephone call. You call up your buddy and specifically want to talk to them. You can say something, and they can respond. You can talk until you hang up the phone. Delegates, in much the same way, create a link between two objects, and you don't need to know what type the  delegate will be, it simply has to implement the protocol. On the other hand, NSNotifications are like a radio station. They  broadcast their message to whoever is willing to listen. Thee radio station can't receive feedback from it's l isteners (unless it has a telephone, or delegate). The listeners can ignore the message, or they can do something with it. NSNotifications allow you to send a message to any objects, but you won't have a link  between them to communicate back and forth. If you need this communication, you should probably  implement a delegate. Otherwise, NSNotifications are simpler and easier to use, but may get you into trouble.
Long Answer:
Delegates are usually a moree appropriate way of handling thiings, especially if you're creating a framework for others to use. You gain compile time checking for required methods when you use protocols with your delegates, so you know when you compile if you're missing any required methods. With NSNotificationCenter you have no such guarantee.
NSNotificationCenter is kindd of "hack-ish" and is frequently used novice programmers which can lead to poor architecture. A lot of times these two features are interchangeable, but more "hardcore" developers might scoff at the use of the NSNotificationCenterr

here is the link of this information(http://stackoverflow.com/questions/5325226/what-is-the-difference-between-delegate-and-notification)

Other link (http://useyourloaf.com/blog/2010/06/06/delegation-or-notification.html)

Comments

Popular posts from this blog

How to Make REST api call in Objective-C.

Launch iPhone simulator without Xcode.

Hacker Rank problem solution