Escaping Vs Non-Escaping Closure Swift

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey hello guys this is and hope everyone is good and and the current density is going good and let's start this video so in this video we are going to see about the escaping a non escaping closure so you see in each and every mobile application we use escaping or non escaping closures and close it is one of the very important thing that we have to use and for service con under closest makes and very important role so but we always have our conclusions like what does escaping closure and what is known is caping closure so in this video and it is a point we can learn escaping and on escaping closure to what did this and what this meant for it's very easy it takes nearly 5 minutes to do so if you are waiting for it please watch this video until this end so let's kick start the video so before going for the video I have already started a created our new project and in the project I just created a view controller which was formally stated by the Xcode so before going to the escaping and on escaping we have to add the two thumb rules we have to learn from it one is so here I have mentioned it no one is keeping closure or synchronous is keeping closure or a synchronous that is known is keeping closure with executed single line one by one and escaping closure will not execute one by one it will be a random composition based on the rules we are proceeding in that particular line and every every time escaping closure or the not default one whatever closure we are creating by default it is a non escaping closure so that's it you have to make in mind only a two point let's go for the creating a function in an example so let me create a fire and I'm going to clear keep a name as non escaping closure I'm going to pick a completion and it's off pipe yes so let me bring up a variable print as closure starts and yeah I'm going to print I am going to call a closure here on escaping brochure STR I'm going to print okay let's see what's happened here so what I basically dislike I have created a function it's called on escaping closure and I have created a completion it's going to be a return nesting so in this start of this closure I have just created a closure starts Brin and closure end once the completion is called I have created a closure called nain so that's it I just called the function here and at the end of the viewdidload I have placed a closure next line it indicates like this particular function will be called after to the non escaping closure function so let's start let's run the code and let's see what's happened here what's going to happen yes we are ready yes it's it's time let's wait for loosening student go yeah please bear with my max speed yeah so this you can see a line called closure start this line executed at first and secondly the closure called its executed second and at last the closure skates in and forth when Li the closure next line gets called so this is the pattern or step-by-step line execution for the not escaping closure now let's go and see the same example for escaping closure and let's see what's going to happen so for that I am going to create there another function with the same procedure but which for is not escaping closure and this calm wind copy this and bestest and change the name escaping closure and yeah I am going to create and dispatch cube so I'm going to call this function so basically what I have did this like I have created a function and this function is going to have and print of start closure and I'm going to print extra closure in function in between meantime under the dispatcher sync after delay time I am going to call a non a completion unless that's it but it's tells me Sarah's like escaping closure cans can capture the non escaping parameter only this indicates like this particular completion handler should be under the type of non escaping closure so let's see under the type of escaping closure so I'm going to make this as escaping closure and I'm going to run this yes it's done so in this you can see like this particular synchronous this is indicates like we used to do a service call and all an API call whatever we can say this will be calls under this particular time of execution so you just consider as like this this particular function a sensor is called so I'm just making the call after a 5.2 seconds of delay and I'm going to call this function so here I'm just a commenting out the escape in on escaping function instead I'm going to call as a skipping function and I'm going to keep in a CSTR and I am going to print this so in escaping closure first its get started and it gets called and its gets in there after that the closure next line gets executed but here let's see what's going to happen for escaping closure now you can clearly understand what this and what will happen here yes I just called the escaping closure now let's see okay yes you can clearly understand like first it's go for star closure and next shoulds go for the enclosure and immediately it's goes for the next line of the code after five seconds of delay it's spent for the line called closure execution so here is the example that you can learn about the closure unknown escaped into ocean so that's a all about the escaping and non escaping it's all about how you use decode if you see any execution which will be coming from the APA or you don't know what time which gets called at that time it will be under the category of escaping and usually whatever closure you will be created it's under the type of known as giving that's a to ramble you have to surely keep in mind if you have learned this two things the escaping a non escaping closure is very much easier to you so that's a my guys I hope this video helped you more a lot thanks for watching this video to support me please subscribe and like the it button thank you so much guys bye-bye
Info
Channel: Mohan Raj
Views: 1,319
Rating: undefined out of 5
Keywords:
Id: RwEUKS3RAGA
Channel Id: undefined
Length: 9min 38sec (578 seconds)
Published: Sun Apr 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.