Swift version: 5.1
Delegates are extremely common in iOS development, but fortunately they are easy to understand: a delegate is any object that should be notified when something interesting has happened. What that "something interesting" means depends on the context: for example, a table view's delegate gets notified when the user taps on a row, whereas a navigation controller's delegate gets notified when the user moves between view controllers.
When you agree to be the delegate for an object, you will almost certainly need to conform to a specific protocol, such as
UITableViewDelete. These protocols will usually have some optional methods that you can implement if you care when something happens, for example, table views can notify you when users deselect a row, but most developers don't care. These protocols may also have some required methods that you must implement.
SPONSORED Catch bugs as soon as they happen and know exactly why a crash occurred by integrating Instabug's SDK in one minute. You will automatically receive device data, network logs, and reproduction steps with every bug and crash report.
Available from iOS 2.0 – see Hacking with Swift tutorial 1
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.