Completion Handlers

Поделиться
HTML-код
  • Опубликовано: 8 сен 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 RUclips Channel
    / stewart Lynch
    CreaTECH Solutions Website
    www.createchso...
    Stewart Lynch's GitHub
    github.com/Ste...

Комментарии • 77

  • @yangxu9767
    @yangxu9767 3 года назад +18

    The clearest explanations on RUclips! 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.

  • @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.

  • @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!!!!

  • @prakashrajak7974
    @prakashrajak7974 11 месяцев назад

    Such an intuitive explanation of Closures.

  • @TrendTechtt
    @TrendTechtt 10 месяцев назад

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

  • @caiyu9373
    @caiyu9373 2 года назад

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

  • @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

  • @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 ruclips.net/p/PLMRqhzcHGw1a4jFHEBitPwCtAgPxWldfy

  • @saurabhtripathi7867
    @saurabhtripathi7867 3 года назад +1

    Very useful tutorial, Completion handlers never looked so easy.

  • @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.

  • @AliJafarov
    @AliJafarov 2 года назад

    Thanks for clean explanation and simple code sample. Very useful

  • @Fitendbeast
    @Fitendbeast Год назад

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

  • @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.

  • @paulshildebrandt
    @paulshildebrandt 3 года назад +4

    I really appreciate this tutorial! Thank you so much!

  • @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

  • @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.

  • @alishenay
    @alishenay 4 года назад +2

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

  • @muhammadusman-vc5re
    @muhammadusman-vc5re Год назад

    May GOD bless on you for this effort.

  • @daniel_munoz_r
    @daniel_munoz_r 3 года назад

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

  • @venugopalreddy6618
    @venugopalreddy6618 8 месяцев назад

    Wow, You explained it so well.

  • @nikhilthite2959
    @nikhilthite2959 2 года назад

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

  • @UMBerto-wj7ch
    @UMBerto-wj7ch 3 года назад

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

  • @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!

  • @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.

  • @moon8300
    @moon8300 3 года назад

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

  • @jasurrajabov
    @jasurrajabov 4 года назад +1

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

  • @noelsoderstrom8706
    @noelsoderstrom8706 2 года назад

    Thank you so much! Great video

  • @denizc1019
    @denizc1019 2 года назад

    great video thanks Stewart!

  • @anatoliyca
    @anatoliyca 2 года назад

    love your explanations!!

  • @user-cp9wl7yf8s
    @user-cp9wl7yf8s 2 года назад

    Thank you very much. It was really useful.

  • @goretushar37
    @goretushar37 3 года назад

    Good Explanation, thanks

  • @amielterence
    @amielterence 2 года назад

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

  • @shashwatsinghchauhan4527
    @shashwatsinghchauhan4527 3 года назад

    Its was really helpful. Thanks

  • @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.

  • @littlechef3692
    @littlechef3692 2 года назад

    great video Stewart

  • @drmucahiderdogan
    @drmucahiderdogan 3 года назад

    Great video.

  • @inspite69
    @inspite69 3 года назад

    Excellent! Liked and subbed!

  • @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.

  • @angelrincon1781
    @angelrincon1781 Год назад

    Thank you!

  • @marlhex6280
    @marlhex6280 2 года назад

    simple wow!

  • @glennmiller394
    @glennmiller394 Год назад

    Thanks!

    • @StewartLynch
      @StewartLynch  Год назад

      You are most welcome. Glad you liked the video.

  • @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 7 месяцев назад

    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  7 месяцев назад +1

      Look in the sources folder for the playground pages.

    • @user-up2fz5gz6x
      @user-up2fz5gz6x 7 месяцев назад

      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!