Swift Programming Language Tutorial Part 6 (Closures)

Watch the followup on Closures after this: https://www.youtube.com/watch?v=3Ob6YG5FRHE
@SkipAllMighty
Best viewed in 4k!
Leave comments on any errata
Covering:
Closures 0:00
Special Thanks to Logan @ loganwright.io

Comments

Maxie yolosen says:

Hi.

I still don’t understand what the .map function does, i’ve taken a look at the ebook and watched this video. I know its some kind of Closure but i just can’t get a grasp on it.

Franky tse says:

how can u get the console output on the right?

Ivan Wang says:

Thanks

Arseny Ivanov says:

Hello. As always, great stuff! Quick question. Why can’t we use the shorted version of the hasPrefixAndSuffix closure like that:

var hasPrefixSuffix: (String, String, String) -> Bool
hasPrefixSuffix = { $0.hasPrefix($1) && $0.hasSuffix($2) ? true : false }
or
hasPrefixSuffix = { $0.hasPrefix($1) && $0.hasSuffix($2) }
 
gives me an error, saying that $2 is used before it is declared. bummer.

Gromix Zeloslaw says:

Great job Wilson. Thanks! Unfortunately, I can not find information on SpriteKit, SKScene, skView.presentScene(scene) and addChild(). Will there be a lesson with these issues?

Michael Nino Evensen says:

Just found your series of tutorials and really loving them! Really really appreciate the work you’ve put into them and really appreciate you putting them out for free. This tutorial on Closures (although me being unfamiliar with them) really explains how they work in both simple examples as well as more complex and abstract situations. Again, well done!

enthusiast says:

in the sort(aBunchOfInts,ReverseSorterFunc) statement, it returns me an error
and Xcode is asking to enter the arguments into ReverseSorterFunc
Why is it different from yours, since I used the same code and got errors

SavannahForood says:

Great video! One question, though — how do you decide whether to use a closure over a function (or vice versa)?

jaydoug63 says:

With Beta6 , in order to recreate the shorthand example I had to use sorted() instead of sort() because sort() requires a reference. 

Tommy Scott says:

Jim and Pam!
Ah… I see what you did there
really miss the office

Dub_Scratch says:

Your tutorial is good, but your screen capture should have enlarged the text greatly. The code text is impossible to read on a phone very difficult to read on an iPad. Most of the screen is white nothing space.

Christoffer Buusmann says:

Skip, this tutorial is really good, but I sometimes really struggle to apply these somewhat ‘made up’ examples, and applying them to real code. Could you maybe make a ‘real world’ example with closures? Maybe implement it in the blog / database tutorial series you are doing? Keep up the good work! – Chris

Andrew Wertheim says:

Hi Skip.. I’m having trouble with the sort() array function in Xcode 8.2. It seems it has been removed from the Swift general function list. Do you know how I would fix this issue? Thanks for your time.

Andrew

Hürol Inci says:

Terrific!

PanjuTorials says:

I am very impressed! Thanks a lot for the explanation. Great presenting!

kollinarasimhaiah narasimhaiah says:

Skip Wilson you taught me all the way swift very easily. Thank you so much.

damn spam says:

I’ve been following along and after 15:45 into the video, I keep getting the error message “NSARRAY IS NOT A SUBTYPE OF INOUT C”. Would you happen to know the solution to this?

Thanks!

Keven Zhao says:

Thanks for the great video but why are you doing this at 5 AM?

Sev Gerk says:

I couldn’t get the sort() function to work as shown. Just an error. I followed your code verbatim but got an error in XCode6b6. Some googling, led me to sorted() function and using it instead did the trick. Was this changed/updated in Swift/XCode? 

chi says:

Brilliant!

Robert Holzapfel says:

Like your tutorials very much ! Good explanations, always starting at a basic point, as a German, I do understand your English pretty well. Thanks a lot ! Greetings from the capital for beer drinkers, Munich !

Chris Robinson says:

I’m getting an error for  sort(aBunchOfInts, reverseSorterFunc). It’s telling me Cannot invoke ‘sort’ with an argument list of type ‘([Int], (Int, Int) -> Bool)’. Everything looks the same as yours; I’m a bit confused. 

reda abakhti says:

awesome tutorIals mate keep up the good work

AdrenalineForMonkeys says:

Great Tutorials about Swift

Dominic Windle says:

I just downloaded the public beta for Yosemite.  Great series of videos and it is really helping me dive straight in with Swift

Fady Sadek says:

Is the lazy keyword is like async in C#

nerdsteamtv says:

thx!

Tommy Scott says:

Great video! Will you make a video about properties? I don’t really understand the lazy things at the end of the video. Thanks!

MiniTekkers says:

Hey skip i love your videos, but can some explain to me what in does, for example string in return. what does the in mean?

jens bendig says:

Thank you Mr. Wilson. The Tutorial is good. But I am not sure if closures are a good thing. From this, i could see that they can lead easily to code, that´s hard to read and they can cause problems, like the reference-cycle. That would be acceptable, if I could see what they are good for. But I couldn´t. What do they help me to do, that I couldn´t do with functions or classes, without trapping a lot of coders into bad code? (I look at this as a great demonstration of how short,dense and implicit code leads to unreadability)

Film Pictures says:

How do I enable console output?

Andres Gonzalo says:

Great tutorials! Thank you so much for sharing!!

Mr. K says:

very useful.. lot of interesting concepts, not only the closures (which were particularly quite confusing to a beginner in swift like me). Thanks!!

kollinarasimhaiah narasimhaiah says:

@Skip Wilson we wanted tutorial on Core Data with Swift

Роман Шамборовський says:

Awesome! Thnx

Maxie yolosen says:

Also, one last question. I still can’t understand this:
if let SomePlanet = PlanetV3.fromRaw(pos)
The exact part is when this is done: if let SomePlanet = (Something).
I think i’ve seen it in loops and others, but it doesn’t make sense. So your making a new variable and making it equal(Not checking if it is equal since that would require two == signs right?) to whatever is on the right side of the statement. And then their is the if statement. 

iglooo102 says:

Any plans for a video about database? SqlLite? thx

Fido N says:

Great Video… Thanks a lot ….

Fury Games says:

at 6:40 why cant you just uses /* and */ instaid of // // // //

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