Delegates in Swift are pretty cool. They work sorta like how inheritance works except that the actions a delegate can carry out are scoped rather than a default inheritance of all attributes or capabilities of the delegator.

One analogy is the President having a delegate to the UN. The delegate can carry out a set of actions on behalf of the President, but can’t really do everything the President can. A delegate is not an instance of what it represents.

The official Apple docs describes Delegation as “a design pattern that enables a class or structure to hand off (or delegate) some of its responsibilities to an instance of another type.” One such a example is AVAudioRecorder , where a class that uses its instance to record audio can’t tell when it is done recording unless it’s a delegate.

AVAudioRecorder uses a protocol to define what a delegate can know and do. As the source code shows below