Excellent example for delegates based on Xcode practice. More useful then other in Playground. Thank you Jonathan!
@jianquanma
3 жыл бұрын
dude, why aren't you more popular?
@swiftarcade7632
3 жыл бұрын
Thx Jian :)
@iAmBeyondGreat
4 жыл бұрын
very clear and concise explanation
@swiftarcade7632
4 жыл бұрын
Glad it was helpful!
@user-wk1mm8dk2x
2 жыл бұрын
Oh your my Rescurer about delegation pattern Thank U !
@swiftarcade7632
2 жыл бұрын
Anytime!
@robinandthedog
2 жыл бұрын
Well done sir, applause.
@swiftarcade7632
2 жыл бұрын
Thank you sir!
@Roam-The-Road
3 жыл бұрын
Hey Man love the video I'm still having trouble wrapping my brain around delegates. Two questions. When you say "Protocol WeatherServiceDelegate" is that a delegate or is it not a delegate until you declare it as a variable? Also what exactly weatherService.delegate = self do. I know in this case self is the viewcontroller but why do you need to make the delegate = the view controller.
@swiftarcade7632
3 жыл бұрын
Hi Zach. This is probably one of the most confusing things about protocol / delegates. What's the protocol and what the delegate. I had the exact same question when learning. What's confusing is that the WeatherService protocol has the word delegate in its name. Make no mistake through. When we define a protocol with that word protocol, that is the interface we are going to talk back to entities that want updates on what we are doing (in this catch fetching the weather). So once we define this protocol, we need to represent it as a variable in our WeatherService - that is what we call the delegate. The delegate is how we talk back to people. So the ViewController, who wants updates one when we've fetched the weather, sets itself as the delegate. Then so long as it implements that protocol, it will get notified when the weather arrives. In summary, I feel your pain. The names are confusing. My advice is to work through an example of your own, draw it out and paper, and eventually you will get an ah ha moment and it will all be clear. Good luck!
@Roam-The-Road
3 жыл бұрын
@@swiftarcade7632 Thank you so much I did what you said and wrote many examples out. I think I understand it a bit more still a bit iffy but much better. Can you check my understanding? The delegate is something that waits be notified of a change then does said change when told about it. In this case the delegate tells the protocol hey I want this information let me know when you have it. The protocol goes to the function requested to change does the task then lets the delegate know here is the information you asked for. The delegate then updates as needed. The whole point of the delegate is some tasks take a while and you need the app to function properly without taking the phone's main resources and CPU power away. If you see any issues in my logic can you let me know please I am trying to wrap my mind around this concept.
@swiftarcade7632
3 жыл бұрын
@@Roam-The-Road That's perfect - you got it! With one slight twist. The purpose of protocol-delegate isn't about performance (this work done by WeatherService can be synchronous or asynchronous). It's that it enables any class to be the receiver of the protocol message. Think about it like this. If Apple came to you and I and asked up to design a Table, and object in the world could communicate with without the Table knowing anything about it's clients... how would we do that? Answer: Protocol-Delegate. That's what makes UITableView, UITextField, and any classes using this pattern amazing. They don't need to know anything about whoever is calling them. So long as they speak that 'protocol', they can talk. Great question. Protocol-delegate isn't easy. But once you understand the mechanics (which you do), and it's purpose (which you also now do), you can see it's beauty, and why it's so widely applied in Apples APIs. Great question Zach. Cheers.
@Roam-The-Road
3 жыл бұрын
@@swiftarcade7632 It all makes sense now. The whole point is just so all you have to do is add it like Superclass and that viewcontroller/struct/class inherits all these useful tools and can perform these actions and you can use it anywhere in your code on any file as long as you have the functions the protocol asks for. Modular design makes so much sense now omg I feel dumb now lol. Thank you man you have more than earned my subscription my view my like and my notifications. Keep up the amazing work and keep educating us new programmers it really does make a difference.
@iAmBeyondGreat
4 жыл бұрын
cool vid. I like the theme
@swiftarcade7632
3 жыл бұрын
I'm glad you like it
@steelwolf180
4 жыл бұрын
This is much easier than the tons of videos that I had watched on it. As they just jump straight to code and used like a "boss" and "intern" angiology to tell you how to do it.
@swiftarcade7632
4 жыл бұрын
Great to hear. Glad you enjoyed it.
@jianquanma
3 жыл бұрын
you must come from Allen's video, lol
@muhammadjonfranky7590
2 жыл бұрын
hey great explanation man but I feel I'm about to cry I'm not getting it, I tried to read documentation I don't understand shit, Have watched shit ton amount of videos about the subject
@swiftarcade7632
2 жыл бұрын
Dont worry about it. Took me a couple of years to really get. Start by not feeling bad. Just go through examples, learn how to do, practice and apply. And then one day the light bulb is going to go on and its going to make perfect sense. Don't worry. It will come. Cheers.
Пікірлер: 21