concept delegate in category ios

This is an excerpt from Manning's book iOS Development with Swift.
Notify the delegate that something is about to happen (usually prefixed with “will”). Notify the delegate that something happened (usually prefixed with “did”). Request permission from the delegate to do something (usually prefixed with “should”).
You could drag a table view object onto your scene’s root view. You’d then need to connect the view controller to the table view—you’d make your scene’s view controller the delegate and data source for the table view and implement any required delegate methods. More on the delegate and data source of the table view shortly.
To use the delegation pattern, you’ll need to set up a delegate protocol that defines a list of all the methods that the delegate should implement. In this case, the protocol will only need one method that will pass a book object to the delegate ready for saving. The table view controller would then adopt the protocol and define itself as the book detail view controller’s delegate. See figure 9.19 for a visual representation of the relationships.
Create the delegate protocol. The naming convention for the delegate of a class is to use the same name of the class with the suffix Delegate. Add the BookViewControllerDelegate protocol to the BookViewController.swift file. protocol BookViewControllerDelegate { func saveBook(_ book: Book) }protocol BookViewControllerDelegate { func saveBook(_ book: Book) }Add a reference to the delegate in BookViewController, and make it an optional. Now, to extract the data that the user has entered for the book, you’ll need to create outlets for each of the elements in the form.var delegate: BookViewControllerDelegate?
The delegate handles additional responsibilities such as selecting and deleting rows or specifying the height of a specific row. The table view will also notify the delegate of certain events, such as when the user selects or edits a row.

This is an excerpt from Manning's book Anyone Can Create an App: Beginning iPhone and iPad programming.
As you’ve learned in previous chapters, these outlets connect the table view to the ViewController. Once connected, the table view will look to the ViewController for the dataSource and delegate properties. With this dialog open, click the open circle for dataSource and drag it to the yellow icon at the top of the ViewController in the storyboard, as shown in figure 15.2.
You added a lot of functionality in the last chapter, but you still haven’t added the functionality you need to let a user create a new LioN. You’re going to do that in this chapter, but you’re also going to use delegates again. You learned about delegates in chapter 16, so refer back there if you need a refresher.
This would work, but it isn’t the right way to do things. That may have been your first instinct, but I want you to try to think more about protocols and delegates. Here’s why: in apps with many views, you may want to call the addNew function from numerous different places in the app. If you think about the Contacts app on your device, you can create a new contact by tapping the + button on the top-right corner. You can also create a new contact from a phone number when someone calls you. This is the same New Contact screen, but it’s called from two different places. If you hardcoded the Done button on the New Contact screen, you wouldn’t know which scene to return to when it’s tapped. Do you return to the Add New Contact scene or the Phone Number scene? This is where our friend the delegate steps in (figure 22.1).
Figure 22.1. You can use the Delegate pattern to ensure that your two ViewControllers aren’t tightly coupled. The AddEditViewController sends a message to the delegate without knowing or caring who the delegate is.
![]()
When the MainViewController creates the AddEditViewController, it sets itself as the delegate, so when the user taps Done on the AddEditViewController scene, the AddEditViewController sends a message to the delegate—and it doesn’t care who the delegate is. This ensures that any scene that conforms to the AddEditView-Controller protocol can call it, set itself as the delegate, and know that the AddEditViewController will return control to it when it’s done. This is called loosely coupled code, and it’s much easier to maintain in the future if and when you want to add more functionality and allow other scenes to call the AddEditViewController scene.

This is an excerpt from Manning's book iOS in Practice.
Whenever an app wants to access images, there’s a single controller to use. It has a setting for accessing the camera or the photo album. Adding this controller to your app and displaying it isn’t a huge effort, but it adds a lot to an app. The controller needs a delegate to call various methods to process the user’s selections.
A table view isn’t much by itself. If you compile and run your project you’ll see an empty table. It needs not only to get data to display from somewhere, but also another class to handle any actions the user initiates. The table view uses a data source to provide its data and a delegate to handle the interactions.

This is an excerpt from Manning's book iOS 4 in Action: Developing iPhone and iPad Apps.
Events can be sent to an object in a way other than via a first responder: through a delegate. This is an object (usually a view controller) that says it will take care of events for another object (usually a view). It’s close kin to a data source, which is an object (again, usually a view controller) that promises to do the data setup and control for another object (again, usually a view).
Delegation and data sourcing are each controlled by a protocol, which is a set of methods the delegate or data source agrees to respond to. For example, a table’s delegate might have to respond to a method that alerts it when a row in the table has been selected. Similarly, a table’s data source might describe what all the rows of the table look like.
Delegates and data sources fit cleanly into the MVC model used by Objective-C, because they allow a view to hand off its work to its controller without having to worry about where each of those objects is in the responder chain.
One critical element we haven’t discussed previously is that you can set a delegate to manage a few common responses. You must follow the UIWebViewDelegate protocol, which lists four methods, described in table 14.6.
There are approximately 14 delegate methods for NSXMLParser. They’re all optional: you need to write delegates only for things you’re watching for.

This is an excerpt from Manning's book iPhone and iPad in Action: Introduction to SDK Development.
Events can be sent to an object in a way other than via a first responder: through a delegate. This is an object (usually a view controller) that says it will take care of events for another object (usually a view). It’s close kin to a data source, which is an object (again, usually a view controller) that promises to do the data setup and control for another object (again, usually a view).
Delegation and data sourcing are each controlled by a protocol, which is a set of methods the delegate or data source agrees to respond to. For example, a table’s delegate might have to respond to a method that alerts it when a row in the table has been selected. Similarly, a table’s data source might describe what all the rows of the table look like.
Delegates and data sources fit cleanly into the MVC model used by Objective-C, because they allow a view to hand off its work to its controller without having to worry about where each of those objects is in the responder chain.
We didn’t discuss one other element when we talked about web views in chapters 3 and 4: you can set a delegate to manage a few common responses. You must follow the UIWebViewDelegate protocol, which lists four methods, described in table 14.6.
There are approximately 14 delegate methods for NSXMLParser. They’re all optional: you need to write delegates only for things you’re watching for. We won’t cover the delegate methods for mapping prefixes, comments, external entities, and many other things of somewhat less importance.

This is an excerpt from Manning's book iPhone in Action: Introduction to Web and SDK Development.
There’s another way that events can be sent to an object other than first responder: through a delegate. This is an object (usually a view controller) that says that it’s going to take care of events for another object (usually a view). It’s a close kin to a data source, which is an object (again, usually a view controller) that promises to do the data setup and control for another object (again, usually a view).
Delegation and data sourcing are each controlled by a protocol, which is a set of methods that the delegate or data source agrees to respond to. For example, a table’s delegate might have to respond to a method that alerts it when a row in the table has been selected. Similarly, a table’s data source might describe what all the rows of the table look like.
Delegates and data sources fit cleanly into the MVC model used by Objective-C, as they allow a view to hand off its work to its controller without having to worry about where each of those objects is in the responder chain.
There’s one other element that we didn’t discuss when we talked about web views in chapters 11 and 12: you can set a delegate to manage a few common responses. You must follow the UIWebViewDelegate protocol, which lists four methods, described in table 20.6.
There are approximately 20 delegate methods for NSXMLParser. They are all optional: you only need to write delegates for things that you’re watching for. We’re not going to cover the delegate methods for mapping prefixes, comments, external entities, and many other things of somewhat less importance.