Completion Handlers

  Рет қаралды 11,931

Stewart Lynch

Stewart Lynch

4 жыл бұрын

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.createchsol.com/StarterPr...
Part 1 iPhone Project
www.createchsol.com/StarterPr...
Reference Video for Static Class functions
• Instance and Static Me...
Stewart Lynch's KZfaq Channel
/ stewart Lynch
CreaTECH Solutions Website
www.createchsol.com
Stewart Lynch's GitHub
github.com/StewartLynch

Пікірлер: 77
@yangxu9767
@yangxu9767 3 жыл бұрын
The clearest explanations on KZfaq! Thanks for sharing this.
@prakashrajak7974
@prakashrajak7974 9 ай бұрын
Such an intuitive explanation of Closures.
@TrendTechtt
@TrendTechtt 8 ай бұрын
Your explanation is simply the best - thank you very much!
@jennywang3113
@jennywang3113 3 жыл бұрын
I rarely comment on youtube videos, but I truly cannot thank you enough for this explanation. Thank you very, very much
@StewartLynch
@StewartLynch 3 жыл бұрын
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 жыл бұрын
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 kzfaq.info/sun/PLMRqhzcHGw1a4jFHEBitPwCtAgPxWldfy
@acmcj
@acmcj 3 жыл бұрын
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 жыл бұрын
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.
@StewartLynch
@StewartLynch 2 жыл бұрын
Glad you enjoyed it.
@Fitendbeast
@Fitendbeast Жыл бұрын
The most precise and well - explained tutorial about C.H I have ever found.
@saurabhtripathi7867
@saurabhtripathi7867 3 жыл бұрын
Very useful tutorial, Completion handlers never looked so easy.
@AliJafarov
@AliJafarov 2 жыл бұрын
Thanks for clean explanation and simple code sample. Very useful
@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.
@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.
@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.
@subhashr.p7643
@subhashr.p7643 3 жыл бұрын
MUCH MUCH CLEAR THAN ANY OTHER TUTORIAL.... NOW I KNOW WHATS COMPLETION HANDLER
@vamsi3877
@vamsi3877 4 жыл бұрын
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
@colbymehmen
@colbymehmen 3 жыл бұрын
Now that's how you make a tutorial video! Awesome job Stewart!
@StewartLynch
@StewartLynch 3 жыл бұрын
Thanks Colby
@nikhilthite2959
@nikhilthite2959 2 жыл бұрын
Perfectly taught tutorial after a long time! Thank you for this man.
@muhammadusman-vc5re
@muhammadusman-vc5re Жыл бұрын
May GOD bless on you for this effort.
@paulshildebrandt
@paulshildebrandt 3 жыл бұрын
I really appreciate this tutorial! Thank you so much!
@venugopalreddy6618
@venugopalreddy6618 6 ай бұрын
Wow, You explained it so well.
3 жыл бұрын
Thank you very much for this video. You are helping a lot.
@alishenay
@alishenay 4 жыл бұрын
Amazing explanations of closures and completion handlers. very much appreciated Stewart.
@StewartLynch
@StewartLynch 4 жыл бұрын
Thanks for the feedback.
@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!
@UMBerto-wj7ch
@UMBerto-wj7ch 2 жыл бұрын
Simply the best explanation, thank you very much! Subscribed.
@StewartLynch
@StewartLynch 2 жыл бұрын
Thanks. I try :)
@anatoliyca
@anatoliyca 2 жыл бұрын
love your explanations!!
@denizc1019
@denizc1019 2 жыл бұрын
great video thanks Stewart!
@moon8300
@moon8300 3 жыл бұрын
Thank you for the Best description of completions handlers! It helps a lot!
@StewartLynch
@StewartLynch 3 жыл бұрын
Glad it was helpful!
@amielterence
@amielterence 2 жыл бұрын
Thank you very much Stewart, a truly great teaching style.👌🏽
@littlechef3692
@littlechef3692 Жыл бұрын
great video Stewart
@noelsoderstrom8706
@noelsoderstrom8706 2 жыл бұрын
Thank you so much! Great video
@user-cp9wl7yf8s
@user-cp9wl7yf8s 2 жыл бұрын
Thank you very much. It was really useful.
@jasurrajabov
@jasurrajabov 4 жыл бұрын
Very useful tutorial, love to see tutorials related to Concurrency. Thank you Steward.
@StewartLynch
@StewartLynch 4 жыл бұрын
On my list
@tushargore8912
@tushargore8912 3 жыл бұрын
Good Explanation, thanks
@inspite69
@inspite69 3 жыл бұрын
Excellent! Liked and subbed!
@drmucahiderdogan
@drmucahiderdogan 3 жыл бұрын
Great video.
@shashwatsinghchauhan4527
@shashwatsinghchauhan4527 2 жыл бұрын
Its was really helpful. Thanks
@randlyce
@randlyce 3 жыл бұрын
This is great!
@emhn5693
@emhn5693 3 жыл бұрын
Best explanation I have found ! Holyy smokess!
@StewartLynch
@StewartLynch 3 жыл бұрын
Take a look at my other videos too. I try to be clear.
@SadSitizen
@SadSitizen 2 жыл бұрын
Thank you!
@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.
@marlhex6280
@marlhex6280 2 жыл бұрын
simple wow!
@pmattos92
@pmattos92 4 жыл бұрын
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 жыл бұрын
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.
@glennmiller394
@glennmiller394 Жыл бұрын
Thanks!
@StewartLynch
@StewartLynch Жыл бұрын
You are most welcome. Glad you liked the video.
@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 5 ай бұрын
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 5 ай бұрын
Look in the sources folder for the playground pages.
@user-up2fz5gz6x
@user-up2fz5gz6x 4 ай бұрын
I downloaded your playgrounds, but the sources folders are empty when I open them in X Code😢@@StewartLynch
@user-up2fz5gz6x
@user-up2fz5gz6x 4 ай бұрын
Thanks for the answer. But even though I downloaded your playgrounds, the Sources folder is empty😢@@StewartLynch
@StewartLynch
@StewartLynch 4 ай бұрын
@@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 4 ай бұрын
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!
@angelrincon1781
@angelrincon1781 Жыл бұрын
Thank you!
Demystifying Completion Handlers and Asynchronous Functions
19:03
Stewart Lynch
Рет қаралды 3,8 М.
map, compactMap flatMap
17:06
Stewart Lynch
Рет қаралды 7 М.
1❤️
00:17
Nonomen ノノメン
Рет қаралды 13 МЛН
Василиса наняла личного массажиста 😂 #shorts
00:22
Денис Кукояка
Рет қаралды 10 МЛН
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 12 МЛН
Swift Completion Handler Tutorial
19:09
Code Pro
Рет қаралды 19 М.
Understanding SwiftUI ViewBuilders
21:57
Stewart Lynch
Рет қаралды 9 М.
How to use Core Data with @FetchRequest in SwiftUI | Continued Learning #14
36:34
How to use escaping closures in Swift | Continued Learning #20
21:56
Swiftful Thinking
Рет қаралды 18 М.
Threads and Grand Central Dispatch in Swift
22:14
Stewart Lynch
Рет қаралды 21 М.
Objective-C Protocol and Delegates- raywenderlich.com
10:15
Bob Nystrom - Is There More to Game Architecture than ECS?
23:06
Roguelike Celebration
Рет қаралды 193 М.
Introduction to Generics in Swift
24:14
Stewart Lynch
Рет қаралды 5 М.
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 5 МЛН
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,2 МЛН
Как слушать музыку с помощью чека?
0:36