Делегат - состоит из:

Делегатор - тот кто ставит задачу.

Тип делегата - протокол. какими свойствами и методами должен обладать делегат.

Делегат - тот кто исполняет задачу.

protocol CoffeMakerDelegate {
func makeCoffe(amount: Int) -> Int
}

class Client {
var name = "name"
var cofeMaker: CoffeMakerDelegate? /- НАШ ДЕЛЕГАТ
func visitCoffeHouse(cofeMaker: CoffeMakerDelegate) {
self.cofeMaker = cofeMaker
}
func goOutCoffeHouse () {
self.cofeMaker = nil
}
func buyCoffe(amount: Int) {
guard let delegate = cofeMaker else {
print("Vi ne v cofeyne!")
}
delegate.makeCoffe(amount: amount)
}
}

struct Officiant: CoffeMakerDelegate {
funk makeCoffe(amount: Int) -> Int {
let price = 350
let count = amount / price
return count
}
}
let officiant = Officiant()
let client = Client()
client.visitCoffeHouse(cofeMaker : officiant)
client.buyCoffe(amount: 2000)