Completion Handlers

Поділитися
Вставка
  • Опубліковано 22 сер 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 UA-cam Channel
    / stewart Lynch
    CreaTECH Solutions Website
    www.createchso...
    Stewart Lynch's GitHub
    github.com/Ste...

КОМЕНТАРІ • 77

  • @yangxu9767
    @yangxu9767 3 роки тому +18

    The clearest explanations on UA-cam! Thanks for sharing this.

  • @jennywang3113
    @jennywang3113 3 роки тому +2

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

    • @StewartLynch
      @StewartLynch  3 роки тому +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 2 роки тому +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 Рік тому

    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  Рік тому

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

  • @prakashrajak7974
    @prakashrajak7974 10 місяців тому

    Such an intuitive explanation of Closures.

  • @TrendTechtt
    @TrendTechtt 10 місяців тому

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

  • @acmcj
    @acmcj 3 роки тому +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  3 роки тому +3

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

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

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

  • @mohamedfawzi6628
    @mohamedfawzi6628 Рік тому

    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  Рік тому

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

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

    Very useful tutorial, Completion handlers never looked so easy.

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

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

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

      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

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

    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  2 роки тому

      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 Рік тому

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

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

    Thanks for clean explanation and simple code sample. Very useful

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

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

  • @subhashr.p7643
    @subhashr.p7643 3 роки тому

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

  • @jlambert12013
    @jlambert12013 Рік тому

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

    • @StewartLynch
      @StewartLynch  Рік тому

      Glad you found the video Jim and found it helpful.

  • @muhammadusman-vc5re
    @muhammadusman-vc5re Рік тому

    May GOD bless on you for this effort.

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

    I really appreciate this tutorial! Thank you so much!

  • @alishenay
    @alishenay 4 роки тому +2

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

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

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

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

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

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

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

  • @venugopalreddy6618
    @venugopalreddy6618 8 місяців тому

    Wow, You explained it so well.

  • @UMBerto-wj7ch
    @UMBerto-wj7ch 3 роки тому

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

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

    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 3 роки тому

    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!

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

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

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

      Thanks Chris. Much appreciated.

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

      @@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  4 роки тому

      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 4 роки тому

      @@StewartLynch
      Cheers Stewart.

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

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

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

    love your explanations!!

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

    Thank you so much! Great video

  • @user-cp9wl7yf8s
    @user-cp9wl7yf8s 2 роки тому

    Thank you very much. It was really useful.

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

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

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

    great video thanks Stewart!

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

    Good Explanation, thanks

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

    Its was really helpful. Thanks

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

    Best explanation I have found ! Holyy smokess!

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

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

  • @pmattos92
    @pmattos92 4 роки тому +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  4 роки тому +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.

  • @littlechef3692
    @littlechef3692 Рік тому

    great video Stewart

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

    Excellent! Liked and subbed!

  • @angelrincon1781
    @angelrincon1781 Рік тому

    Thank you!

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

    Great video.

  • @glennmiller394
    @glennmiller394 Рік тому

    Thanks!

    • @StewartLynch
      @StewartLynch  Рік тому

      You are most welcome. Glad you liked the video.

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

    simple wow!

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

    This is great!

  • @AnkitSingh-wq2rk
    @AnkitSingh-wq2rk 3 роки тому

    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  3 роки тому

      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.

  • @user-up2fz5gz6x
    @user-up2fz5gz6x 6 місяців тому

    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  6 місяців тому +1

      Look in the sources folder for the playground pages.

    • @user-up2fz5gz6x
      @user-up2fz5gz6x 6 місяців тому

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

    • @user-up2fz5gz6x
      @user-up2fz5gz6x 6 місяців тому

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

    • @StewartLynch
      @StewartLynch  6 місяців тому +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 6 місяців тому

      thanks a lot!!🤍@@StewartLynch

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

    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  3 роки тому

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

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

      @@StewartLynch Wonderful thanks Stewart!

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

    Thank you!