WTF is a closure ? 

Your going about your normal programming life. Everything is fine, your using functions and classes and variables, and etc. And you’ll be thinking “I got this programming thing pretty much in the bag”

But then you see “it” what “it” is your not sure. Its something coming out the side of your function … OMG is looks like another function. A function against a function ???

We all know what a function is, it is just piece of code that we can use in different places. It some times takes in varables and spits them out. This is all “normal”, however what if I told you that you could return a function from a function ? Or even add a function as a input value ? Pretty crazy right ?

Some of you out there might be thinking, “why would you need this ? stop making things soo complicated !” Well if you want your applications to run asynchronously, your gonna wanna use closures when ever you do something that takes alot of time.

So the use case would go something like this:You wanna log someone in, and execute something else as soon as it finishs, without freezing up the UI (in a iOS app).

Instead of doing it the standard way of writing the code that needs to be executed right after the method call. You can just pass the login function, another function to execute once done.

The in depth code will come in part two.

Hope you found the theory behind it easy to understand 😅

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s