UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How do you watch the videos and which video/book best covers Closures?

Forums > Swift

Hello all, I just subscribed today! I believe I have purchased everything here lol. I have all of the books loaded onto my Kindle, and I have the videos saved to my dropbox. I do have the "Unwrap" app, but I believe it is designed to be self contained and not related to anything I purchased correct? So curious if there is a good way to watch the videos via a self contained app? I have them all loaded into a "Hacking With Swift" folder on my dropbox, but I thought I would check with you folks to see how you all do it?

Lastly, I have another online Swift course I am taking and I am up to the section on Closures, but I want to now see how HWS teaches that part of Swift. SO I am just trying to see which book(s) or video(s) would best cover that?

Thank you all!

2      

Hi,

If you want to specifically read about closures, Pro Swift in my opiniom would be the place to start.

3      

Have you done the 100 days (which are free) there is a section about Closures on day 9

4      

Welcome, i know you will find many places in HWS+ section where you can find details of closure, also you are doing another course, good luck with that , but i want to tell you a few simple points that helped me understand closure a little

1) Closure are themselves function(they are refernce type) and they are used to perform tasks like functions perform.

2) We need them because just like in maths , before we move to next step to solve an equation , we need data from an earlier step in our algorithm to solve a problem.

3) For eg, if i want to show an image and the image is on network , which means i need to make a network call, the network call can fail or take time due to slow internet or image might not be there, here we use closures, you must have seen @escaping in many functions

4) What we are doing here is performing the task of making a network call, wait for a correct response or error and react accordingly.

5) Once we get a response , we provide it to any parameter the closure might have and then use the parameter from the closure inside the function , which will then use the image to display in an Image object.

6) So, closures are used in this way to not stop the process inside our app, but to gracefully wait for data we need to proceed in our algorithm to achieve our task.

7) Closure create a strong reference as they hold on to values even out of their scope , so not allowing the garbage collection as the object always keeps pointing to some entity , we use weak or unowned keywords to make them capable of being cleaned up once the function inside which they are being created has finished its job.

8) They are very useful, but can take a lot of time for out mind to train to how to use them , very useful tool indeed, it took me a lot of time to understand them, but might take even longer to use them , its like a tool there in front of me but i need more practise to find when to use them.

Fun Fact - accoring to a book from Tanenbaum a famous computer science author, closures were discovered by chance, when computers scientists found data being retained and not getting cleaned up in memory , this lead to a rather pleasant but unintended discvoery of a type we now call closures.

Good luck in your journey of app development

3      

@SplintaWM Thank you! @NigelGee yes I watched that video last night after I posted, it was extremely helpful!

@AmitShrivastava Thank you so much, that explination was very helpful. I think it will take a while for me to grasp this all. I am coming from a C# background, which I now see that a Closure is very similar to C#'s Lambda...I just never used a Lambda but I am at best a junior C# developer lol

Can any of you answer my other part of my question about the videos? Do you all have a preferred way of watching them?

Thank you all!

2      

There are a couple of videos

Stewart Lynch Introductions to Closures in Swift, Understanding Swift Trailing Closure Syntax

Sean Allen Swift Closures Explained

This might help. Remember Closures are difficult so looking or reading from different souces may help

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.