Completion Handlers

Sdílet
Vložit
  • čas přidán 12. 09. 2024
  • In this video I am going to explore CompletionHandlers. What are they? How can we create them, and how to use them. They are a fundamental concept in programming and are often referred to as callbacks.
    As we proceed, we will also learn about escaping completion blocks, and trailing closures.
    We will start with a playground as an introduction to develop the concept and end up with looking at a simple iPhone app to reinforce our learning.
    Starter Projects:
    Part 1 Playground
    www.createchso...
    Part 1 iPhone Project
    www.createchso...
    Reference Video for Static Class functions
    • Instance and Static Me...
    Stewart Lynch's CZcams Channel
    / stewart Lynch
    CreaTECH Solutions Website
    www.createchso...
    Stewart Lynch's GitHub
    github.com/Ste...

Komentáře • 77

  • @yangxu9767
    @yangxu9767 Před 3 lety +18

    The clearest explanations on CZcams! Thanks for sharing this.

  • @acmcj
    @acmcj Před 3 lety +9

    Wow. This was amazing. The explanation, the progress from simple examples to more complex ones to real life scenarios. Also love the rectangles bouncing around the code to help show the various code flows. Amazing. If all your content is like this, I’m watching it all!!!!

    • @StewartLynch
      @StewartLynch  Před 3 lety +3

      Glad you liked it! Yes, they are all like this LOL. At least I try.

  • @jennywang3113
    @jennywang3113 Před 3 lety +2

    I rarely comment on youtube videos, but I truly cannot thank you enough for this explanation. Thank you very, very much

    • @StewartLynch
      @StewartLynch  Před 3 lety +1

      You are welcome Jenny. I learn through teaching so these videos are made as much for my benefit as they are for anyone else. I refer often to the videos I have made over the past year. I try to craft my explanations so that they can be easily understood.

  • @andrewsridhar3829
    @andrewsridhar3829 Před 2 lety +1

    Read and watched everything on completion handlers and closures INCLUDING Apple's documentation but still was incredibly confused -- UNTIL this video (and your one on closures). Thank you!!!!

  • @roh9934
    @roh9934 Před 2 lety

    Steward man, you're the best Swift Tutor I have come across on all of Internet. I hope you have made videos on concurrency.

    • @StewartLynch
      @StewartLynch  Před 2 lety

      I have actually. But I did them for the CodeWithChris channel. You can find them at czcams.com/play/PLMRqhzcHGw1a4jFHEBitPwCtAgPxWldfy.html

  • @prakashrajak7974
    @prakashrajak7974 Před 11 měsíci

    Such an intuitive explanation of Closures.

  • @caiyu9373
    @caiyu9373 Před 2 lety

    so clearly, so easy to understand, so friendly to beginner. very helpful, really thanks.

  • @TrendTechtt
    @TrendTechtt Před 10 měsíci

    Your explanation is simply the best - thank you very much!

  • @vamsi3877
    @vamsi3877 Před 4 lety +3

    Best explanation i have ever seen.Thankyou please make more n more content.👏👏

    • @StewartLynch
      @StewartLynch  Před 4 lety

      Thanks, If you have any suggestions for topics, let me know. I want to focus on single topic ideas that give new developers some problems

  • @saurabhtripathi7867
    @saurabhtripathi7867 Před 3 lety +1

    Very useful tutorial, Completion handlers never looked so easy.

  • @nelsonalva
    @nelsonalva Před 2 lety

    I bet it must have taken you a lot of time to create this video. It's all so well explained. You have become my #1 Swift youtuber. Thanks!

    • @StewartLynch
      @StewartLynch  Před 2 lety

      Thanks. Yes, I spend a lot of time preparing for and recording my videos. Often a 30 min video takes 3 days to complete.

  • @Fitendbeast
    @Fitendbeast Před rokem

    The most precise and well - explained tutorial about C.H I have ever found.

  • @mohamedfawzi6628
    @mohamedfawzi6628 Před rokem

    God I wish I watched this video back when I started! Absolutely perfect! the best explanation ever. Thank you, now I don't have to explain this to anyone I'll just share this video with them

    • @StewartLynch
      @StewartLynch  Před rokem

      Thanks again Mohamed. I really appreciate the positive feedback. It keeps me motivated.

  • @AliJafarov
    @AliJafarov Před 2 lety

    Thanks for clean explanation and simple code sample. Very useful

  • @colbymehmen
    @colbymehmen Před 3 lety +1

    Now that's how you make a tutorial video! Awesome job Stewart!

  • @alishenay
    @alishenay Před 4 lety +2

    Amazing explanations of closures and completion handlers. very much appreciated Stewart.

  • @paulshildebrandt
    @paulshildebrandt Před 3 lety +4

    I really appreciate this tutorial! Thank you so much!

  • @jlambert12013
    @jlambert12013 Před 2 lety

    Wow. This is the first time I’ve understood. Thank you.

    • @StewartLynch
      @StewartLynch  Před 2 lety

      Glad you found the video Jim and found it helpful.

  • @nikhilthite2959
    @nikhilthite2959 Před 2 lety

    Perfectly taught tutorial after a long time! Thank you for this man.

  • @subhashr.p7643
    @subhashr.p7643 Před 3 lety

    MUCH MUCH CLEAR THAN ANY OTHER TUTORIAL.... NOW I KNOW WHATS COMPLETION HANDLER

  • @kenjyfukuda
    @kenjyfukuda Před 3 lety

    Thanks for your step-by-step explanation from the very very basic to the basic but practical use case. Great help for the beginners.

  • @Randor10
    @Randor10 Před 3 lety

    Wow, what a lifesaver! I'm having the exact problem reloading a tableview with data from my PHP server. I've watched about 15 videos on closures and completion handlers, but none of them really clicked in my head as to what was going on. Your methodical approach to teaching really helped make it click. I'll be using your code as a template for adding completion handlers to several places in my app. Thank-you! Liked and subbed!

  • @jasurrajabov
    @jasurrajabov Před 4 lety +1

    Very useful tutorial, love to see tutorials related to Concurrency. Thank you Steward.

  • @UMBerto-wj7ch
    @UMBerto-wj7ch Před 3 lety

    Simply the best explanation, thank you very much! Subscribed.

  • @moon8300
    @moon8300 Před 3 lety

    Thank you for the Best description of completions handlers! It helps a lot!

  • @daniel_munoz_r
    @daniel_munoz_r Před 3 lety

    Thank you very much for this video. You are helping a lot.

  • @muhammadusman-vc5re
    @muhammadusman-vc5re Před rokem

    May GOD bless on you for this effort.

  • @pmattos92
    @pmattos92 Před 4 lety +3

    Hi, Stewart! I’m really enjoying these videos. Even though I’m already an iOS developer who works with Swift on a daily basis I still learn some new things from them. But mostly, you are a very good presenter/educator. Keep up the great work! On a separate note: I don’t know why, but this video’s audio seems to be playing only through the left channel on my earphones. I don’t know if this is intentional, or just a side effect of how you recorded your voice or encoded the video, but it’s a bit distracting to me so I wanted to let you know.

    • @StewartLynch
      @StewartLynch  Před 4 lety +1

      Thanks for your comments, especially since you are an experienced developer. Much appreciated. I just plugged in my earbuds to listen to this video and there does seem to be a bit more coming through on the left channel, but it is not exclusively on the left channel, but definitely more. Not sure how that happened as I recorded on both channels. I will try to monitor that in subsequent videos before I post. Thanks again.

  • @chrispy104k
    @chrispy104k Před 4 lety

    Best description of completions handlers I have seen so hats off to you Stewart.

    • @StewartLynch
      @StewartLynch  Před 4 lety

      Thanks Chris. Much appreciated.

    • @chrispy104k
      @chrispy104k Před 4 lety

      @@StewartLynch
      I have a request that you might consider in a future video if you think that it's interesting enough to be a topic.
      The scenario I had in mind is as follows:
      The initial ViewController is a TableViewController and is embedded in a NavigationController.
      A second ViewController is added to serve as a means of adding a new record or edit an existing record. It would have a Cancel button and a Save button in the navigation bar. A fairly typical scenario I would have thought.
      In the case of "Edit", lets say you pass a few parameters to the AddEditViewController:
      mode - which is an enum - (.edit or .add),
      the array which is the data source of the tableView
      and the other is the index which you can derive from didSelectRowAt.
      So you would call the AddEditViewController by:
      if let editVC = storyboard.instantiateViewController(identifiedBy: "AddEditView") as? AddEditViewController {
      editVC.mode = .edit
      editVC.dataArray = dataArrray
      editVC.rowIndex = indexPath.row
      navigationController.pushViewController(editVC, animated: true)
      }
      In the case of "Add", which is triggered by a navigation button "+", which might have the code:
      @objc addNewRecord() {
      if let addVC = storyboard.instantiateViewController(identifiedBy: "AddEditView") as? AddEditViewController {
      addVC.mode = .add
      addVC.dataArray = dataArrray
      navigationController.pushViewController(addVC, animated: true)
      }
      }
      In .edit mode you would Save the data to the array passed in and in .add mode you Save the new item to the array (append). In either case, how would you pass back the array which had been modified? Using a completion handler?

    • @StewartLynch
      @StewartLynch  Před 4 lety

      chrispy_wa In this case, I would inject the enum and a closure into the pushed VC and in that vc handle the add/edit by using Service Class function that would handle all data CRUD operations. The closure would just be a func that would either update or reload the tableview depending on the case. Funny you should mention this idea as I was thinking that this would be a good follow up to this tutorial. I have a couple different ones planned but I will add this to the list.

    • @chrispy104k
      @chrispy104k Před 4 lety

      @@StewartLynch
      Cheers Stewart.

  • @venugopalreddy6618
    @venugopalreddy6618 Před 9 měsíci

    Wow, You explained it so well.

  • @amielterence
    @amielterence Před 2 lety

    Thank you very much Stewart, a truly great teaching style.👌🏽

  • @denizc1019
    @denizc1019 Před 2 lety

    great video thanks Stewart!

  • @anatoliyca
    @anatoliyca Před 2 lety

    love your explanations!!

  • @noelsoderstrom8706
    @noelsoderstrom8706 Před 2 lety

    Thank you so much! Great video

  • @goretushar37
    @goretushar37 Před 3 lety

    Good Explanation, thanks

  • @user-cp9wl7yf8s
    @user-cp9wl7yf8s Před 2 lety

    Thank you very much. It was really useful.

  • @shashwatsinghchauhan4527

    Its was really helpful. Thanks

  • @littlechef3692
    @littlechef3692 Před 2 lety

    great video Stewart

  • @inspite69
    @inspite69 Před 3 lety

    Excellent! Liked and subbed!

  • @emhn5693
    @emhn5693 Před 3 lety

    Best explanation I have found ! Holyy smokess!

    • @StewartLynch
      @StewartLynch  Před 3 lety +1

      Take a look at my other videos too. I try to be clear.

  • @drmucahiderdogan
    @drmucahiderdogan Před 3 lety

    Great video.

  • @angelrincon1781
    @angelrincon1781 Před rokem

    Thank you!

  • @AnkitSingh-wq2rk
    @AnkitSingh-wq2rk Před 3 lety

    Hi Stewart,
    Thank you for your clear and concise explanation i recently started iOS Development so i had a doubt regarding threads as you said API calls run on a background thread and UI-related work should be done on main thread.
    In my case, I am fetching data from an endpoint using alamofire and wanted to use completion handlers but I am somewhat confused ...in your video you intentionally made your function run in the background thread and then called a specific block of code on the main thread I wanted to ask in my API call do I have to do the same? making the request in the background thread explicitly or it is done automatically?
    Apologies for my bad English

    • @StewartLynch
      @StewartLynch  Před 3 lety

      Network calls with Alamo fire are always executed on a background thread automatically. I just released a new video today on this topic that may add some clarification too.

  • @marlhex6280
    @marlhex6280 Před 2 lety

    simple wow!

  • @glennmiller394
    @glennmiller394 Před rokem

    Thanks!

    • @StewartLynch
      @StewartLynch  Před rokem

      You are most welcome. Glad you liked the video.

  • @user-up2fz5gz6x
    @user-up2fz5gz6x Před 7 měsíci

    Amazing tutorial, thankyou! Can you please tell me what extension (or whatever this is😅) which allows you to add those blocks with explanations to your playgrounds?

    • @StewartLynch
      @StewartLynch  Před 7 měsíci +1

      Look in the sources folder for the playground pages.

    • @user-up2fz5gz6x
      @user-up2fz5gz6x Před 7 měsíci

      I downloaded your playgrounds, but the sources folders are empty when I open them in X Code😢@@StewartLynch

    • @user-up2fz5gz6x
      @user-up2fz5gz6x Před 7 měsíci

      Thanks for the answer. But even though I downloaded your playgrounds, the Sources folder is empty😢@@StewartLynch

    • @StewartLynch
      @StewartLynch  Před 7 měsíci +1

      @@user-up2fz5gz6x Sorry. I thought you were referring to something else in another playground. You are probably referring Takto the Markup that I use in that playground. Take a look at this developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_markup_formatting_ref/

    • @user-up2fz5gz6x
      @user-up2fz5gz6x Před 6 měsíci

      thanks a lot!!🤍@@StewartLynch

  • @randlyce
    @randlyce Před 3 lety

    This is great!

  • @colbymehmen
    @colbymehmen Před 3 lety

    Stewart how do you format the titles like that in the playground? Can you point me in the right direction to figure that out. Thanks.

    • @StewartLynch
      @StewartLynch  Před 3 lety

      Does this help? www.thomashanning.com/xcode-markup-for-playgrounds/

    • @colbymehmen
      @colbymehmen Před 3 lety

      @@StewartLynch Wonderful thanks Stewart!

  • @SadSitizen
    @SadSitizen Před 2 lety

    Thank you!