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.
SAVE 20% ON iOS CONF SG The largest iOS conference in Southeast Asia is back in Singapore for the 5th time in January 2020, now with two days of workshops plus two days of talks on SwiftUI, Combine, GraphQL, and more! Save a massive 20% on your tickets by clicking on this link.
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.