Delegation in Swift
Boss those classes
4 min readApr 30, 2020
Prerequisites:
- Be able to produce a “Hello, World!” iOS application (guide HERE)
- Be comfortable with Classes in Swift (guide HERE)
- Some understanding of callbacks (closures) in Swift would be useful(guide HERE)
- I’ve used segues to pass information in part of the demo (guide HERE)
Terminology
Delegation: A pattern that enables a class to delegate responsibility for some actions to an instance of another class
Protocol: A blueprint on methods, properties and requirements to suit a piece of functionality
UITableView: A view that presents data using rows arranged in a single column
Why delegate?
The real life proxy
So the word delegate in the English language is about giving responsibility for a task to another person.
Your boss might delegate opening the office to a deputy, particularly if the boss is on vacation.