Swift Delegate Protocol Pattern Tutorial - iOS Communication Patterns Part 1

Поділитися
Вставка
  • Опубліковано 29 гру 2024

КОМЕНТАРІ • 571

  • @seanallen
    @seanallen  4 роки тому +7

    Watch Next - iOS Take Home Project - Job Interview Practice - Free Preview - ua-cam.com/video/MSIe2y6Fee8/v-deo.html

    • @mrmillmill
      @mrmillmill 3 роки тому

      Hey Sean, I bought your iOS Dev course from your site and man I really wish I would’ve bought it sooner. I am a firm believer in the pay to play mentality and your course is just one more reason for that. I’ve just gone through the first five videos and you are very thorough, clear, and straight to the point giving the student everything they will need. I also like that the whole course is done programmatically without a storyboard. I honestly cannot say enough great things about what I’ve experienced so far.

    • @PavelPalancica
      @PavelPalancica 7 місяців тому

      Thanks for the video, Sean! There is a minor issue with this line:
      var selectionDelegate: SideSelectionDelegate!
      Should be:
      weak var selectionDelegate: SideSelectionDelegate?
      There is no guarantee selectionDelegate will always be non-nil inside SelectionScreen class (unless it's a private property initialized based on a SideSelectionDelegate argument passed in a custom init(delegate: SideSelectionDelegate) {...} method).
      There are some exceptions when we must indeed use strong delegate properties, but in most cases we should use weak var delegate: SomeDelegate?

  • @ericamillado
    @ericamillado 7 років тому +90

    The "intern" and "boss" analogy is so helpful, keep these videos coming!

    • @seanallen
      @seanallen  7 років тому +3

      Glad you enjoyed it, Erica! I've always been pretty good at coming up with analogies to explain things... it's a fun way to teach.

    • @samrakkaus8178
      @samrakkaus8178 6 років тому +1

      this is the first analogy for protocols/delegates that finally made me understand the concept. Thank you Mr. Allen.

    • @mryup6100
      @mryup6100 6 років тому

      agree

  • @lamdbich
    @lamdbich 7 років тому +7

    Finally someone who values my time so that I don't have to speed up the videos. Keep it up.

  • @gianluigidautilia6417
    @gianluigidautilia6417 3 роки тому

    i have watched all youtube videos on this topic on youtube. Most of them you fall asleep, or you have some guy trying to give sense to his thoughts. 99,99 % of the times are just pure confusion. Here Sean in 13 minutes goes so straight and clear to the point that even you are a total beginner you will understand it. Impressive. He speaks fast, but i have noticed that you need to keep this peace and speed of words not to get too lost in thoughts. Amazing job man. thanks.

  • @thomasdermaris4984
    @thomasdermaris4984 7 років тому +101

    You have to declare your delegate var as weak to avoid reference cycles. This is one common question to interviews too..

    • @seanallen
      @seanallen  7 років тому +106

      Hey Thomas, thanks for the feedback! I appreciate you guys keeping me honest. Anytime you put your code out there for the world to see, there's bound to be some missteps. To your point, you are correct if you declare your protocol as a class protocol, like `protocol SideSelectionDelegate: class', then you need to declare the delegate variable as 'weak' to avoid retain cycles. However, if don't declare your protocol as 'class' you're allowing your protocol to be adopted by structs, which are value types, and therefore don't really work with reference counting. This blog post provides a good explanation: useyourloaf.com/blog/quick-guide-to-swift-delegates/ . It's a clarification I neglected point out in my video. Thanks for bringing it up!

    • @thomasdermaris4984
      @thomasdermaris4984 7 років тому +19

      Thanks for your answer Sean. To tell you the truth I wasn't aware of that..

    • @anupdsouza
      @anupdsouza 7 років тому +7

      I had the exact same question when I began watching this video, glad I scrolled through the comments to find your reply Sean :)

    • @wilsonbalderrama
      @wilsonbalderrama 7 років тому +2

      My first thought (I need to test it, will do it tonight) about this is that we are dealing with class instances and that's why I think there are memory leaks.

    • @wilsonbalderrama
      @wilsonbalderrama 7 років тому +3

      OK I tested and I didn't find a strong reference cycle I believe that's because BaseScreen instance doesn't have a property that's referring to the SelectionScreen instance.

  • @AmitThakur-eg8kb
    @AmitThakur-eg8kb 3 роки тому +1

    one of the best iOS teacher on this planet. Good job Sean.

    • @seanallen
      @seanallen  3 роки тому

      Thanks for the kind words, Amit.

  • @ebubeawachie
    @ebubeawachie 3 роки тому +1

    Oh my goodness!!! This is the absolute best explanation of Delegates and protocol I have seen on the internet. Thanks so much Seal Allen. You be doing so much for us Swift noobs.

    • @seanallen
      @seanallen  3 роки тому

      Glad it was helpful, Mark!

    • @ebubeawachie
      @ebubeawachie 3 роки тому

      @@seanallen Sean, I’m having this issue of lack of confidence. I just started this journey some months ago band I’m switching from a career in medicine (I’m a Veterinary Doctor with an MSc in Veterinary Physiology but I’ve always loved technology).
      Sometimes it feels like I can’t just cut it. I’ve always been good academically graduating best in high school and college but coding is just a different ball game.
      I’ve always been able to understand things really really quickly but some things here just take a while to grasp.
      Is this normal for everyone?
      Are there any insights you can share for dealing with this?
      Sorry for the long read.

    • @seanallen
      @seanallen  3 роки тому

      Yes, this is normal. Coding is hard to learn at first, but just like any skill, the more you do it the more comfortable you get. I don't have any secret tip or anything. It's all about putting in the time and repetitions (just like any other skill). Then one day, things just start clicking.

  • @snebold
    @snebold 7 років тому +4

    Hey, I love your tutorials! I think the speed is fine, but I especially appreciate the fact that you don't waste time launching Xcode and setting up the UI like so many other tutorials out there. You just get to the meat of the matter. Thanks!

    • @seanallen
      @seanallen  7 років тому +1

      +Bill Snebold Thanks, Bill. I hear ya on that. I remember learning myself, and I always hated all the setup on EVERY video. As you've seen, i just do a quick review of my starter project, then on to he good stuff.

  • @thomasgarayua4979
    @thomasgarayua4979 2 роки тому

    Thank you, thank you, thank you... It's amazing how great your analogies are. It really helped me understand the flow of data and how everything works. I was having a moment a few days ago thinking "Maybe Software Engineering isn't for me. I don't understand this stuff and I can't do it. I should honestly give up." Its great to see that there's people out there like you that can articulate in non-technical terms to make understanding this stuff that much easier. Thanks again, you've earned one more subscriber!

  • @ryanjin8343
    @ryanjin8343 4 роки тому +1

    I was using a static variable to pass data back and forth yesterday. I knew there had to be a better way, and after watching this video, I immediately went back to my project and changed it to a delegate-protocol pattern. The code is so much cleaner. Thank you so much Sean!

    • @seanallen
      @seanallen  4 роки тому

      Happy to clear that up, Ryan!

    • @chrism8943
      @chrism8943 2 роки тому

      Why is this a better way than passing a variable? I just don't understand... it doesn't seem straight forward, like "beating around the bush." I just don't get, WHY use delegates? Isn't there a simpler way?

  • @BodhiMoosa
    @BodhiMoosa 6 років тому +1

    I spent the entire afternoon (and now night) tackling the problem of understanding delegates and their application. I've read article after article, downloaded and attempted to analyze projects provided by others, and read official documentation, but everything I've read and seen thus far seems to attempt to explain this concept to people who already understand this concept. Your video here actually explains the concept and relationships very well to someone like myself who is trying to get into coding.

    • @seanallen
      @seanallen  6 років тому

      Happy to hear you found it helpful, M 👍

  • @lilyshevchenko7048
    @lilyshevchenko7048 7 років тому +3

    You, Sir, are my hero! I am going through a coding bootcamp and our platform laid out info about protocols and delegates in such dry, confusing manner that I was struggling to understand what goes where until I saw your demo. In less than 10 minutes, everything snapped into place for me! Love the easy to understand and engaging example and love boss/intern analogy. Thank you for sharing your know-how.

    • @seanallen
      @seanallen  7 років тому +1

      Happy to hear it helped you, Lily. I struggled with Delegates/Protocols for the first 6 months of my career, so I know how ya feel!

  • @djskywalkerremix
    @djskywalkerremix 7 років тому +1

    I have been struggling with this for about two months now and you just made it so clear for me and I now understand it !! Thank you so much, you sir are a gent and a scholar !!

    • @seanallen
      @seanallen  7 років тому

      That's awesome to hear, Neil. Happy to help!

  • @dorianbrown1588
    @dorianbrown1588 6 років тому +2

    One of the best iOS instructor! This tutorial helped me understand after countless hours understanding protocols and delegates!

    • @seanallen
      @seanallen  6 років тому

      I appreciate the kind words, Dorian 🙌

  • @hanzularaza4564
    @hanzularaza4564 6 років тому +2

    Sean you are unfolding the most difficult topics of iOS development with so much ease , after your videos everything makes more sense to me .. Thanks Buddy

    • @seanallen
      @seanallen  6 років тому

      Glad you found it useful, Hanzula. I've got a lot more videos 😀

  • @mashfique
    @mashfique 7 років тому +7

    This whole video was a "Aha" moment for me! Your videos are really good for reviewing concepts! Please keep uploading them :)

    • @seanallen
      @seanallen  7 років тому

      +Mashfique Anwar Thanks! More on the way!

  • @JamesEtallaz
    @JamesEtallaz 2 роки тому

    I love your pacing. Straight to the point. And fast. Every time. Well done.

  • @atheros07
    @atheros07 4 роки тому +1

    Clearest explanation of delegates in Swift I’ve ever found. Thanks Sean!

    • @seanallen
      @seanallen  4 роки тому

      Thanks! Glad you enjoyed it 😀

  • @stomachcontentz
    @stomachcontentz 6 років тому +3

    Sean - love your stuff. It's great when you find someone who thinks in a similar way to you which makes the information transfer fast and effective. Maximum respect so much for taking your time to make these videos.

    • @seanallen
      @seanallen  6 років тому +1

      Thanks for the kind words, Christian! Motivates me to keep going!

  • @mauricio2099
    @mauricio2099 7 років тому +1

    Thanks Sean, This is the best explanation of delegates by far. The Boss/Intern analogy is exactly what I needed to fully understand the concept. Great Stuff!

    • @seanallen
      @seanallen  7 років тому

      Thanks Mauricio! Glad it helped. Appreciate you sharing via tweet as well.

  • @MikhailFederov
    @MikhailFederov 3 роки тому

    10:44 My heart sank when you said “This function is automatically getting called”. That’s the one part I don’t understand about delegates but it was hand-waved away. Every video so far o delegates does this

  • @infinite5837
    @infinite5837 5 років тому +4

    Great video!
    I'm currently building an application and this has made my life way easier.
    I was using notifications and observers. However, I started to notice that my code was getting messy.
    So I took the time to learn how protocols work and restructured my application.
    Great decision and good learning experience.
    Thank you!

    • @seanallen
      @seanallen  5 років тому

      Happy to hear you found the video helpful, Sergio 😀

  • @timharris72
    @timharris72 7 років тому +3

    This is the best explanation I have seen so far of what delegates do. I do Qt programming (Python) and use delegates all the time for table views but it was always difficult for me to explain the Swift syntax to other people or understand the Swift syntax using delegates as it is a little bit different although the concept is the same. Thanks for the help.

    • @seanallen
      @seanallen  7 років тому

      Glad to hear the video helped out, Tim!

  • @syedmahmudahmed8921
    @syedmahmudahmed8921 3 роки тому

    Short, simple and precise. This is the best tutorial on delegate protocol communication pattern I've found as a beginner. Bonus points for referencing Star Wars. Thanks man.

  • @blackjaquar
    @blackjaquar 7 років тому +1

    One of the best Delegates/Protocol tutorials I've seen. Thanks

    • @seanallen
      @seanallen  7 років тому

      Much appreciated Bahe! Happy to hear the video helped!

  • @stevefreed3646
    @stevefreed3646 6 років тому +1

    Thank you so much! I could not find any helpful videos explaining protocols. Everyone elses videos weren't clear on how to use them in different situations, your video really helped me understand how to use them in all types of situations.

    • @seanallen
      @seanallen  6 років тому

      Happy to hear it helped, Steve!

  • @cometmace
    @cometmace 7 років тому +1

    Nice, concise explanation.
    In the boss code, "we're safe to force unwrap that because we know we have the UIImage..." @7:35. Someone else taught me "Protect yourself against mistyping a UIImage you know you have by safely unwrapping it..." You would hope you'd catch a runtime error like that during testing, but stuff happens.
    p.s. I just noticed Ben Sullivan's comment. That would solve this issue.

  • @arnavgaur9034
    @arnavgaur9034 3 роки тому +1

    The best explanation I have seen so far. Great content Sean!

    • @seanallen
      @seanallen  3 роки тому +1

      Thanks for the kind words, Arnav 😀

  • @firstjamesryu
    @firstjamesryu 3 роки тому +1

    So close to 100k subscribers. Congratulations in advance, Sean!

  • @satyam3993
    @satyam3993 6 років тому +1

    Thank you so much!! Even after reading bunch of Medium posts, I wasn't clear with the concept of delegates. Thank god I found your life saving video :) Keep making videos, coz you are really good at it!!

    • @seanallen
      @seanallen  6 років тому

      Thanks Satyam! Glad it helped you out! I know this is a tricky topic.

  • @TreyCox1
    @TreyCox1 6 років тому +3

    I just had my "aha!" moment while watching this video. Super helpful, Sean. Thanks for these videos and for the great podcast.

    • @seanallen
      @seanallen  6 років тому +1

      Awesome! Love those moments 😀

  • @faizuddin.mohammed
    @faizuddin.mohammed 5 років тому +1

    HIGHLY RECOMMENDED VIDEO!
    Just had a question regarding Communication Protocols in my technical interview with a large company today.
    I knew the whole concept but couldn't put it into words, wish I had watched the whole series earlier.
    Thanks for the video, Sean.

    • @seanallen
      @seanallen  5 років тому

      Glad it was helpful... although a little too late it sounds like. 😀

  • @amdizle28
    @amdizle28 6 років тому +1

    Keep making Tutorials Sean, you helped me choose my career path and your videos are extremely efficient for learning! Started with your iOS interviews video and now I work as an iOS Developer, dreams do come true and your videos continue to help every time I need to learn!!!

    • @seanallen
      @seanallen  6 років тому +1

      That's awesome to hear Adam! Congrats on the new job!

  • @GameAssetsGarden
    @GameAssetsGarden 3 роки тому +1

    Thank you so much for making this tutorial! I was struggling for hours but then I watched your video and got my code working shortly after.

    • @seanallen
      @seanallen  3 роки тому +1

      Happy to hear it was helpful to you project!

  • @sravk245
    @sravk245 4 роки тому

    Your video tutorials and the comments left by viewers are very informative. I attended an in person iOS course and couldn't really follow my instructors explanation of this topic. Thank you for such a straight forward explanation, very easy to follow.

    • @seanallen
      @seanallen  4 роки тому

      Thanks Srav! Glad you are enjoying the content!

  • @PhontaineJudd
    @PhontaineJudd 7 років тому +1

    Enjoy watching your videos. They're presented in a clear, logical way that makes it easy for me to understand. Thank you!

    • @seanallen
      @seanallen  7 років тому

      Glad you enjoy them, Phontaine!

  • @YummyHealthyCookingShow
    @YummyHealthyCookingShow 7 років тому +1

    One day i asked god to teach me iOS and he had sent you... Stay blessed @Sean Allen

  • @MarcosVicente0
    @MarcosVicente0 4 роки тому +3

    Hey, Sean! I was really struggling to understand Communication patterns with Delegate protocol. This example and explanation just made very simple to understand. Im definitely
    a video learner. Thank you! Take care!

    • @seanallen
      @seanallen  4 роки тому

      Glad the video helped you out, Marcos!

  • @CASMANWHAT
    @CASMANWHAT 6 років тому

    How do you use delegates for the initial screen? where let's say my home screen is a tableview and the moment they click on the cell, the data shows on the next screen? This ex. works for me for second screen binding to first but what about first binding to second? I tried it and I got nil for unwrapping the delegate. Thx for the tutorials they're really good! Gonna support your book!

  • @nileshjdarji
    @nileshjdarji 3 роки тому

    Man I still sometimes don't get my head to wrap around delegates and protocols concept. But luckily I have this video of yours bookmarked so I always go back to watch it again to make myself clear. Awesome boss and internal anology. Thank you.

  • @TechyMom-ft
    @TechyMom-ft 2 роки тому +1

    Your teaching method is amazing, loved the video.

    • @seanallen
      @seanallen  2 роки тому

      Thanks for the kind words, Hiba 😀

  • @pavanbhupatiraju6653
    @pavanbhupatiraju6653 7 років тому +1

    Great analogy that clears the air on how delegates work.

    • @seanallen
      @seanallen  7 років тому

      Happy it helped, Pavan!

  • @shoebmoin10
    @shoebmoin10 6 років тому +10

    This was the first time i read all the comments of a video , they were very informative thanks for replying all the questions sir :-)

    • @seanallen
      @seanallen  6 років тому +4

      I can't always get to all of them (some comments are very detailed questions), but I try to get to as many as I can. Happy you appreciate it!

  • @trevorduersch2278
    @trevorduersch2278 6 років тому +2

    Sean, I always appreciate these videos that you produce. They are very enlightening and have helped me a lot in my iOS development. I'm in the process of switching my career from a PeopleSoft HCM developer to an iOS developer and your videos have pushed me further than I could imagine! Thanks for what you do and keep it up!

    • @seanallen
      @seanallen  6 років тому

      That's awesome to hear, Trevor! Thanks for the motivating words. Happy to hear I can help. Keep at it!

  • @chrispy104k
    @chrispy104k 5 років тому +1

    It's an oldie but a goodie. Great stuff Sean.

    • @seanallen
      @seanallen  5 років тому

      Always fun to go back and revisit 😀

    • @chrispy104k
      @chrispy104k 5 років тому

      Sean Allen
      Truth is that the content was something that I didn’t fully understand despite the courses I have done. Your description gelled immediately so my hats off to you. Happy to have filed that one away for the future.

    • @seanallen
      @seanallen  5 років тому +1

      Many of the topics in programming and iOS development will take repeated study. Glad it was helpful!

  • @Tenly2009
    @Tenly2009 3 роки тому

    I’ve watched a video about delegates/protocols every 3 months for the past 2 years and have always tuned out with glazed eyes about halfway through and walked away more confused than when I started. It was always difficult for me to envision the demo use case - but this time, I think I finally get it! (Probably because I was using Singletons and didn’t need to pass data between viewcontrollers - I just updated the global object and then had each VC “refresh” when something else changed a value)
    But in my current project, I’ve tried to avoid using singletons and instead I’ve been adding a variable named parentVC to all of my selection screens and then having the callingVC set it equal to “self” right before I present it - that way I have a link to the callingVC. But then in the selection screen class, I’d have to attempt to unwrap the parentVC against 2 or 3 different viewcontrollers to figure out which one it was called by and then call a function in it called “didTapWhatever()”. It was messy and felt wrong - but I didn’t know any other way.
    Now I see how using a delegate simplifies that and makes it much cleaner! Thanks Sean!!!

  • @vuduong4
    @vuduong4 6 років тому +2

    Been struggling with this for a while now, finally makes sense. Thanks Sean!

    • @seanallen
      @seanallen  6 років тому

      Happy to help, Vu 👍

  • @charmisolanki2891
    @charmisolanki2891 7 років тому +1

    great tutorial ... i am new in IOS development .. your tutorials are really helpful , keep making videos for beginners

    • @seanallen
      @seanallen  7 років тому

      Thanks Charmi! Glad you enjoyed it.

  • @firstjamesryu
    @firstjamesryu 6 років тому +2

    This video still saves lives one year after its release...

    • @seanallen
      @seanallen  6 років тому +1

      Hehe, yeah, it's one of my most viewed videos.

  • @nusretalikzlaslan8063
    @nusretalikzlaslan8063 3 роки тому

    Great video! I finally get the idea of the protocols and delegates. Analogy worked really well. Thank you.

  • @3ilz
    @3ilz 4 роки тому

    The boss vs intern analogy is genius!

  • @cholschuh
    @cholschuh 4 роки тому +1

    Another one of your videos helping me out of a bind!! Thank you!

    • @seanallen
      @seanallen  4 роки тому

      Happy to help, Chris 😀

  • @petermattheisen9856
    @petermattheisen9856 2 роки тому

    Perfect!!! Sean, thanks a lot for making this mechanism so clear and easy to understand. Your code and explanations are straightforward and bring it to the point.

  • @JasonMitchellAZ
    @JasonMitchellAZ 5 років тому +1

    Just came across this video again... Wow, just over 2 years since you posted it! Still love the "intern and boss" analogy! 💯

    • @seanallen
      @seanallen  5 років тому +1

      It's a classic... I talk insanely fast... but other than that, I like it.

    • @rebeloper
      @rebeloper 5 років тому +1

      Yes, these things are evergreen

  • @ashiquepuliyakkode5584
    @ashiquepuliyakkode5584 6 років тому +1

    Superb.. You just put an end to my 3 weeks of stress...! Thanks...

    • @seanallen
      @seanallen  6 років тому

      Happy to hear it helped, Kristoffer 👍

  • @WhatIsThisAllAbout
    @WhatIsThisAllAbout 5 років тому

    watching all the videos, got three interview this Saturday.

    • @seanallen
      @seanallen  5 років тому

      Good luck! Hope they help.

    • @WhatIsThisAllAbout
      @WhatIsThisAllAbout 5 років тому

      Thanks Sean. Your videos are amazing. Took a dose of your videos and went high to interview.

  • @MrEcsplorer
    @MrEcsplorer 7 років тому +4

    Very nice videos. I like your speed. Very logically explained and very supportive analogies.

    • @seanallen
      @seanallen  7 років тому

      Thanks Timo! Glad you enjoyed the video!

  • @ucmasshankar
    @ucmasshankar 5 років тому +1

    Thanks for the clear and crispy explaining protocol.

  • @farahmassuh7323
    @farahmassuh7323 3 роки тому

    Thank you boss (Sean Allen). I (intern/delegate) will implement this lesson right away!

  • @jachuonbass
    @jachuonbass 6 років тому +1

    Dude, you speak so fast sometimes is hard to keep up but great stuff, finally it's all making more sense to me now! Thanks for sharing your knowledge!!

    • @seanallen
      @seanallen  6 років тому +1

      Yeah, these are my older videos. I’ve worked on that in my new ones. It’s much better. See on the comments in this video... this was probably the worst one, lol

    • @jachuonbass
      @jachuonbass 6 років тому

      I've seen this kind of stuff declare in this fashion right in the middle of a delegate file:
      @objc protocol DataDelegate : class {
      @objc optional func newPrices()
      @objc optional func newHistory()
      }
      does it make any big difference or would you say is pretty much the same principle?

    • @seanallen
      @seanallen  6 років тому +1

      This is declaring the functions as optional. Which means that if you conform to the protocol, you don't HAVE to implement the functions. Where as if you didn't make them optional, and you conformed to the protocol, then implementing the functions would be required.

  • @TourGuideFTW
    @TourGuideFTW 7 років тому +2

    Love the way you explain, please keep it up!

    • @seanallen
      @seanallen  7 років тому

      Thanks Simon! More videos on the way!

  • @King-DieGo-12
    @King-DieGo-12 2 роки тому +1

    the tutorial was too good, watched a couple before this one, but only this made sense to me:)

    • @seanallen
      @seanallen  2 роки тому

      Glad it finally makes sense now, Akash!

  • @govindsuryawanshi9052
    @govindsuryawanshi9052 5 років тому +1

    Simply great explanation with rapid speed and a good example(intern - boss)

    • @seanallen
      @seanallen  5 років тому +1

      Thanks Govind! Glad it was helpful👍

  • @TheHy6xD
    @TheHy6xD 7 років тому +4

    omg, I finally understood how it works, thank you very much!

    • @seanallen
      @seanallen  7 років тому

      Glad to help, Dosbol!

  • @javadbacker481
    @javadbacker481 5 років тому +1

    Love your to the point coding videos

    • @seanallen
      @seanallen  5 років тому +1

      Thanks Javad! I do my best to eliminate all the irrelevant stuff.

  • @foocux
    @foocux 7 років тому +2

    Great video bro, you're such a good teacher!

    • @seanallen
      @seanallen  7 років тому

      +Leonardo Emilio Thanks for the kind words! Glad you enjoyed the video.

  • @codewithmusto
    @codewithmusto 4 роки тому +1

    You explain really well, Sean. Great video, thanks a lot.

  • @aldovernando4395
    @aldovernando4395 3 роки тому +1

    Really great analogy and easy to understand! Love ur channel! I am your observer now 😄

    • @seanallen
      @seanallen  3 роки тому

      Glad you enjoyed it, Aldo!

  • @chudq
    @chudq 7 років тому +1

    Nice video! Further extension to this is to have another protocol implemented by Boss so that the communication between Intern and Boss is purely on protocol. For example, Boss would like to pass data (delegate or others) to Intern.

    • @seanallen
      @seanallen  7 років тому

      Thanks for the kind words, D Chu! And you're correct, you could extend this implementation that way.

  • @seanallen
    @seanallen  7 років тому +4

    Have a question about Delegates/Protocols? Leave a comment, I'm happy to help!

    • @alexmymo
      @alexmymo 7 років тому +2

      Sean Allen I did have a similar question around the weak reference in the boss VC but managed to see your response. So in short because the protocol wasn’t limited to just class conformance ie it could be adopted by a struct which is a value type this won’t create a retain cycle when adopted by a class or a struct. But if it was limited to classes we must use a weak ref. Sorry if I am repeating myself that’s how we drum home the info lol. Awesome videos though and I’ve subscribed! Nice job!

    • @seanallen
      @seanallen  7 років тому

      +Alex McPherson Yup. You got it!

    • @alexmymo
      @alexmymo 7 років тому

      Sean Allen awesome thanks man!

    • @ilovecoding9286
      @ilovecoding9286 7 років тому

      you speak so fast

    • @arjunbemarkar7414
      @arjunbemarkar7414 6 років тому

      I am new to Swift so sorry if this question sounds stupid, but what is a delegate

  • @Guapoaggie
    @Guapoaggie 6 років тому +1

    Your videos are so helpful Sean! Just wanted to say thank you

    • @seanallen
      @seanallen  6 років тому

      Thanks! Glad you enjoy them 👍

  • @johntamch
    @johntamch 7 років тому +3

    This is by far the best video I found explaining protocols. Thanks Sean and love your interview question videos.

    • @seanallen
      @seanallen  7 років тому

      That's awesome to hear, John! Glad you're enjoying the interview question videos series.

  • @rollingchamp
    @rollingchamp 2 роки тому

    Best video on this topic by far. Thank you

  • @LaurentShala
    @LaurentShala 7 років тому +1

    Such a great video. Very informative and fast paced (in a good way).

    • @seanallen
      @seanallen  7 років тому

      Thanks Laurent! Glad you enjoyed the video and pace!

  • @sumitbaneedits2721
    @sumitbaneedits2721 4 роки тому

    I am actually an intern learning swift. I am here after my Trainer sent me to learn communication patterns.

  • @mutasemwahbeh6954
    @mutasemwahbeh6954 4 роки тому +1

    Thank you Sean, your explanation was great !

  • @crampsalot
    @crampsalot 6 років тому +1

    Great video Sean, thank you ! Subject matter and how you present it (clear, concise) is *very* helpful.
    I have seen (and used in some cases myself) the delegate/protocol pattern where the 'boss'
    class maintains a collection/array of delegates instead of just one. This means that it can support
    one-to-many.
    I don't see this special one-to-many delegate/protocol case useful for the case of a popup communicating
    the result of a choice made, but there are some non-UI cases where this may be suitable - I took this
    approach numerous times in the past instead of the observer/notification pattern as I was porting some
    event listener logic from Java which made use of Java interfaces and since Java interfaces are very similar
    to Swift protocols, I latched on to it.
    Obviously there are some minor differences from your example to support this one-to-many delegate/protocol
    case, notably logic to support multiple delegates - from having to add/remove multiple delegates, to
    invoking *all* the delegates' functions when the time comes. I do this by simply iterating over a delegates
    array, calling each delegate's function.
    QUESTION: I was wondering if you have see this one-to-many case of delegate/protocol usage and if you know
    of any pitfalls to doing it this way vs using the observer/notification pattern.
    Keep up the good work ! Appreciate this video and all the other ones you have made.

    • @seanallen
      @seanallen  6 років тому

      Hey crampsalot, I have not seen this in use in the handful of production apps I've worked on. The projects I've been involved in have pretty much stuck to the delegates/protocols for one-to-one and notifications/observers for one-to-many. Unfortunately, i can't really chime in with an opinion here.

    • @crampsalot
      @crampsalot 6 років тому

      Sean Allen thank you - appreciate the response.

  • @PetersTW
    @PetersTW 7 років тому +1

    Great video!! Best protocol explain I found.
    One question, in 9:02, why selectionVC got selectionDelegata property ?

    • @seanallen
      @seanallen  7 років тому +1

      The SelectionScreen has a variable called selectionDelegate. Here at 9:02 we are setting that variable to the current view controller.

  • @cometmace
    @cometmace 7 років тому +1

    You set up your button action to present the selectionVC. When I tried to recreate the program from scratch to practice what I've learned, I did a control-drag from the button to the selection view and got a segue. I put the = self code into the prepare(for: segue...) function. Is there any value in one approach rather than the other?
    I love the pace and scope of these tutorials.

    • @seanallen
      @seanallen  7 років тому

      Hey Cometmace, they are basically the same. One is a storyboard way of doing it, and the other is just doing it in code. You get the same result.

  • @jaypacker
    @jaypacker 6 років тому +1

    Sean, I'm so appreciative of the videos! I'd be grateful if you could answer one question though.
    What if instead of a static Selection Screen, we wanted a dynamic one? For example, let's pretend that our Base Screen has two buttons, a "Choose your side" and a "Choose your favorite character." We want the latter to present Chewbacca and Han Solo. But we want to REUSE the Selection Screen in both cases.
    How can we setup our Selection Screen to pass in different images, strings, and colors? Do we somehow make the Selection Screen to also be an intern of the Base Screen? Can data go back and forth like this?
    I'm using your example here, but I have a very real need. I'm making my first app, and I have a screen with a UITextField that takes a number which is needs to pass back to the Base Screen. I can see how I can easily do this with Protocols, as you've explained in your tutorial. BUT... I present this screen from two *different* places on the Base Screen, so I need each Number Selection Screen to be different. I need to pass in three values to my Number Screen: 1) a title (presented with a label), 2) a minimum value of the number, and 3) a maximum value of the number (used later in a function to check the range.)
    Not knowing any better, I resorted to making these three items properties of the Number Selection Screen View Controller. Then, when I go to the Selection screen, in the same place where we do this:
    selectionVC.selectionDelegate = self
    I can add things like:
    selectionVC.title = "Enter a number"
    selectionVC.minimum = 1
    selectionVC.maximum = 100
    But it seems to me my code has gotten ever uglier and more dependent on each other the more I add.
    Is there a way to do exactly what you're doing in this tutorial, but let is go both ways, so that the Base Screen passes values to the Selection Screen first, then the Selection Screen does exactly what you've shown us in this tutorial, returning the user's selection?
    Hope that wasn't too wordy for you. Wanted to be clear.

    • @seanallen
      @seanallen  6 років тому

      To be honest with you Jay, I'm not sure if I followed all that to know EXACTLY what you're looking for in order to provide a correct answer. It's tough to answer these types of questions via UA-cam comments. I do offer 1-on-1 video call consulting/coaching to review code. If your interested in that, DM me on twitter @SeanA0400 and we can discuss the details.

    • @seanallen
      @seanallen  6 років тому

      Can two views be delegates of each other? Yes, that's possible.

  • @michaelszabo3071
    @michaelszabo3071 3 роки тому

    As soon as I see its a video made by Sean it gets the like.

  • @raimitis
    @raimitis 7 років тому +1

    Dear Sean, Sorry I am not a native English speaker and I did not fully understand what you mean at 9:21. Can you explain in other way the line 24 what exactly means selectionVC.selectionDelegate = self. I understand that selectionVC.selectionDelegate is variable, but equals to self. How to understand this? Does it means BaseScreen also now has variable selectionDelegate?

    • @seanallen
      @seanallen  7 років тому +3

      Hey Raimonds, I'm happy to explain in another way. Hope this helps.
      - selectionVC is an object we create on line 23. This is where we create the instance of SelectionScreen that we will present.
      - selectionVC has a property that we created as a variable on the SelectionScreen called selectionDelegate
      - When we use 'selectionVC.selectionDelegate', we are actually setting the variable on the SelectionScreen before presenting it.
      - On line 24, we set selectionVC.selectionDelegate = self. Another way to say this would be selectionVC.selectionDelegate = BaseScreen. (Because we are on the BaseScreen at this point, self = BaseScreen).
      - To clarify, BaseScreen DOES NOT have a variable called selection delegate.
      I hope that helped. If you still need clarification, please feel free to ask. We'll figure this out.

    • @raimitis
      @raimitis 7 років тому

      Sean Allen Thank you so much for helping us to understand Swift. I think it gets more clear now, but I have some questions more and if you are not against I will write you. :)
      Once again I really appreciate your help.

    • @seanallen
      @seanallen  7 років тому +1

      Feel free to reach out via email, Raimonds.

    • @raimitis
      @raimitis 7 років тому

      Thank you so much for your help!

  • @chrisstromberg6527
    @chrisstromberg6527 6 років тому +1

    Brilliant explanation!

    • @seanallen
      @seanallen  6 років тому

      Glad you got value out of it, Chris!

  • @Traoreee
    @Traoreee 7 років тому +14

    Everytime i start to watching your video, i think the video speed is 1.25... Every single time i fall in this mistake haha

    • @seanallen
      @seanallen  7 років тому +3

      Haha, I've been working on slowing down a bit. Thanks for watching!

    • @coalwood6901
      @coalwood6901 6 років тому

      yea, no more Sean vids for me....sounds like a gravel hauler droning down the road.

    • @roygalaasen
      @roygalaasen 5 років тому

      Putting 50% playback speed makes him sound drunk lol

    • @michaelkarbasch7619
      @michaelkarbasch7619 4 роки тому

      I am struggling too haha and on top of that i am a german native speaker which makes it even tougher but great video - thanks for explaning 👍🏻

  • @ThinkCleverAndSmart
    @ThinkCleverAndSmart 6 років тому +1

    I wish you made videos like this for MacOS development too. Very clear. I know most of this is similar, but I get some errors that just doesn't make sense.

    • @seanallen
      @seanallen  6 років тому

      I haven't done any Mac development as of yet. Just iOS

    • @ThinkCleverAndSmart
      @ThinkCleverAndSmart 6 років тому

      Ok. Would be nice to hear if you ever want to start making some simple apps for the Mac! Swift is extremely similar for both!

  • @MrHyde-kc3dv
    @MrHyde-kc3dv 5 років тому +1

    really good explanation thanks Sean!

  • @shiliangzhang5172
    @shiliangzhang5172 7 років тому +1

    i dont usually comment but when i do it's because its a great video!

    • @seanallen
      @seanallen  7 років тому

      Glad you enjoyed it!

  • @swiftlandacademy3193
    @swiftlandacademy3193 5 років тому +1

    Nice video! Easy to understand

    • @seanallen
      @seanallen  5 років тому

      Glad you enjoyed it, Alan!

  • @mauricejulesm
    @mauricejulesm 4 роки тому +1

    Still helpful in 2020!
    Thanks Sean.

  • @valentinzech8800
    @valentinzech8800 4 роки тому

    Best video on this topic I've seen so far. Thank you!

  • @Globalhorns
    @Globalhorns 7 років тому +1

    Love how you explain code, good job!

  • @Aevatheone
    @Aevatheone 7 років тому +1

    Nice and simple explanation. Thanks!

    • @seanallen
      @seanallen  7 років тому

      Thanks Martin. Glad you enjoyed it!

  • @Mo__Hazz
    @Mo__Hazz 6 років тому +1

    Thanks dude. It helped me understanding it much better.
    I just had an exam in Swift where I was asked about delegates and couldn't answer.🙁

    • @seanallen
      @seanallen  6 років тому

      Happy to help Mohammed!

  • @mohamedosama6697
    @mohamedosama6697 5 років тому +1

    you are amazing bro , please come back to swift , we need you

  • @s.d.1091
    @s.d.1091 3 роки тому

    Great video! how would I apply this to enabling a button on the first/intern view controller? I keep trying different things with no luck

  • @nipponese
    @nipponese 6 років тому +2

    I would "like" this video five times if I could.

    • @seanallen
      @seanallen  6 років тому

      Thanks nipponese. Glad you enjoyed it 😎

  • @mohammadgz4546
    @mohammadgz4546 Рік тому +1

    best explaintion of delegate and protocols 👌👌👌❤❤❤

    • @seanallen
      @seanallen  Рік тому +1

      I have an updated better version on my channel here - ua-cam.com/video/qiOKO8ta1n4/v-deo.html

    • @mohammadgz4546
      @mohammadgz4546 Рік тому +1

      @@seanallen thanks but i have already watched that, but didn't got the point before
      i'll watch that again.

  • @klausjakobsen3160
    @klausjakobsen3160 7 років тому +1

    Hi Sean. Thanks you made it very clear. Keep it up

    • @seanallen
      @seanallen  7 років тому

      +Klaus Jakobsen Glad you enjoyed it, Klaus!

  • @DavidNoyMusic
    @DavidNoyMusic 3 роки тому

    Very useful, simple and easy to understand video, thanks!

  • @preshanthangavelu6495
    @preshanthangavelu6495 4 роки тому

    Dear Allen , I’ve enrolled in your basic course , getting the hang of it . Step by step .
    Question - can we create an app for our employees in office to check in and out during office hours and indicate the world load they have done for the day ?