I am new to iOS. I have come to know about these two approaches for message passing but I am unable to choose between them.
-
1if you want the one to one call use delegates , if you want one to many use notification – Anbu.Karthik Oct 04 '16 at 11:19
-
Possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Ashutosh Dave Oct 04 '16 at 11:22
-
Depends on requirements. If you want to pass data from one class to another then use Delegate. If you want to add a listener within your app then add Notification.As per my view depends on requirements. – Gagan_iOS Oct 04 '16 at 11:24
2 Answers
Conceptually, a delegate is a helper or an object that does part of the work for some other object that it can't do by itself. Frequently there will be a protocol involved and the object that has a reference to the delegate expects it to behave in a predefined way or, at least, in a way that's specific to the needs of the calling class.
Example: All the methods defined for a UITableViewDelegate
are specific to table activity.
Notifications are more about state changes. The object sending the notification doesn't need help to do its work, it just lets other objects know about a change in case they want to react. If nothing else cares about the change, that's OK.
Example: An object that receives a UIApplicationDidBecomeActiveNotification
may do whatever the developer needs at that time, not just things related to the UIApplication
.

- 30,888
- 4
- 42
- 57
Delegate Patterns are mostly used because of delegate Object knows in which class delegate methods are implement. Delegate Object contains the references for object of that Class where you want to perform you task.
In Notification Patterns , simply a notification is broadcast over the entire classes and each class is search for the observer methods implementations So it took more time to search observer methods as compare to Delegate pattern.

- 651
- 5
- 16