The Complete Swift 3 Tutorial with Bob: Lesson07_Closure

The Complete Swift 3 Tutorial with Bob: Lesson07_Closure

Lesson_07 What is Closure

In the previous lesson, we had to create a function and name the function in order to use it. However, we can significantly write less code by introducing closures. Closures are self-contained chunks of code without a name and passed around. Closures can take input(s) and return values just like a function.

We Heart Swift: Chapter 9: Closure:
The Swift Programming Language – Closure:
FuckingSwiftBlockSysntax – Swift closrues and functions:
Aidanf – Learn Swift: Functions and Closures:

Stay Connected:

Swift Course:
Learn Swift with Bob:

You may email me at to receive a 25% discount link.


Aitor Pagán says:

Nice job but still not enough to understand closures and its uses. For best understanding take a look to this:–ud576

Nimish Sharma says:

hey, great tutorial and can you please make a video on @escaping closure? i think it is confusing to a lot of people including me. thanks in advance:D

Srdjan Knezevic says:

why im i paying private classes…

Ebuka Perez says:

Try to keep distance from the mic i could hear you breathing lool

Marcos Felipe says:

is there any slack for iOS ?
I need one !
Gimme something, please =]

Ish Singh says:

Great video Bob, it really helped me understand the uses of functions with closures. Keep up the good work. If you add a video on completion Handlers that would be great. Thanks again dude

Dinh Quang Luong says:

You do realize that it’s nothing different from function right?

sonali biranwar says:

Can you please give a session on Completion handlers/Blocks in swift 3?

Vitor Ferraz says:

Bob why do you use
var sayHi2:(String)-> String = { name in
return “Hi (name)”
sayHi(“Vitor 2”)

and not like this:

var sayHi = {(name:String) -> String in
return “Hi (name)”


There is any difference between the two?
Thanks !!! Great Video by the way and awesome links on the description it help me a lot!

trapped ByGiraffe says:

Sry, but there is no advantage of using a closure in the examples you’ve shown. “You don’t have to memorise the word ‘func’ and you don’t have to name it.” Instead you have to use ‘var’ and name that. Also, the last version is 0 shorter than the first version. You are showing the syntax only, but no advantages (as you say you do). Using this in context with more complex operations or using them as trailing closures would show that off.

feastures says:

Why (Int, Int) -> (Int) and not (Int, Int) -> Int?

Marcos Felipe says:

That amazing !!! The your videos teaching Swift.
I watching everything o/
I’m fall in love with it.

Can I help with little thing ?
In closure, on short method. We can remove the “return” . For example :

var sumClosure: (Int, Int) -> (Int) = {$0 + $1}

That work ! 😉
And we dont put return :)

Dont be hurt with me. I’m sorry for anything !

Bob the Developer says:

@Ghassan Jaam, I listened to you and it is ready now :)

turbohoodie says:


Nicolás Fernández says:

Talking about best practices, when should I use closures and when should I use functions?

Darshan says:

I don’t have mac machine so what is alternative way to practice this tutorials

The Pretty Unicorn says:

A question: Is a closure basically just a simpler way of writing a function? Or is there anything I can do with closures that I can’t do with functions?

feastures says:

The func sum() is NOT more concise! In programming what counts is writing something that’s easy to understand, not something that’s concise.

nahid Raihan says:

Thank you so much!


Hi Bob, I am trying to create multiple playground file to store my algorithms for future references, but I am having an error “expressions are not allow at the top level:, any clues? thanks

Write a comment


Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours