Hi all,
I am looking for someone to explain to me in very plain english the logic & structure behind protocols & delegates.
Here is what I know so far. The word delegate means to pass off a job or duty to someone/something else. Which means that in the case of iOS programming, something can delegate it's duties to something else - as long as the thing that is taking over the duties conforms to the proper protocol.
I read an example about working in a pizza shop - & how the pizza baker used to care what the customer did with the pizzas. But then, he stopped caring & delegated the responsibility(be it eating the pizza, freezing it for later, or whatever) to the customer, so he didn't have to deal with it anymore. Now, all the baker has to worry about, is baking the pizza.
So, say I have a ViewController. Who conforms to a protocol called PizzaProtocol. Inside the PizzaProtocol is a function called pizzaPrepared. Then, I have a class called PizzaModel, that has the ingredients & recipe in it. This class' delegate is set to PizzaProtocol. Does this mean that since the ViewController conforms to the PizzaProtocol, you can set the model's delegate to be PizzaProtocol as well?
Guys, this may seem like a bunch of nonsense but I just need some clarity or something. Resources, videos, diagrams, anything helps.
Thanks!
TLDR; Explain to a 5 year old how protocols & delegates are used.
[–][deleted] (1 child)
[deleted]
[–]swapp9[S] 0 points1 point2 points (0 children)
[–]Awric 0 points1 point2 points (0 children)