Skip to content
0:00 / 0:00

#closures#swift#swiftui

Introductions to Closures in Swift

Stewart Lynch

27K subscribers • 2 videos on Hallway

YouTube

Beginner. No background in the topic needed.

13K views5 years ago2 recommendations

Programming languagesSwiftFunctional programming

Stewart Lynch explains Swift closures, covering syntax, trailing closures, escaping closures, and capturing values.

In this video, we are going to dive into closures to really try to understand what they are, and how they are used in Swift. We will start by understand the closure syntax and simple closures We will follow that by seeing how we can use closures as parameters in our functions and what trailing closures and escaping means. We will also look at how Closures are used in SwiftUI all the time. We will finish by looking at creating functions that can return closures and how closures can capture values. If you want to support my work, you can buy me a coffee :) ko-fi.com/stewartlynch ******** Download my StewartLynch YouTube Channel Application - Free *********** stewartlynch.gumroad.com/l/obsjz Table of Contents: Introduction 1: 51 Simple Closures Trailing Closures Closures in SwiftUI Escaping Closures Functions returning closures Capturing Values Starter Project Files: createchsol.com/StarterProjects/UnderstandingClosures.playgr… Completed Project: github.com/StewartLynch/IntroductionToClosuresInSwift_Comple… Other references: Playground ViewModifier for SwiftUI github.com/StewartLynch/PlaygroundViewModifier Completion Handler video: youtu.be/JmPbnuJxzHg Other References: Stewart Lynch's YouTube Channel: youtube.com/StewartLynch Stewart Lynch on Twitter: twitter.com/StewartLynch CreaTECH Solutions Website: createchsol.com Stewart Lynch's GitHub: github.com/StewartLynch

Why it's here

2 people recommend this

What people say. Recommended as an excellent tutorial for understanding closures in Swift and SwiftUI.

u/danielt1263in r/swift • Recommends

On “Best way to understand closures”

Hmm, closures have nothing to do with recursion. Maybe this will help: struct Example { let add1 = { (a: Int, b: Int) in a + b } func add2(_ a: Int, _ b: Int) -> Int { a + b } } In the above, `add1` and `add2` are identical in every way. You call them exactly the same way, you can pass them as arguments in exactly the same way. It's likely that the compiler even compiles them the same way. A great tutorial is in the official Swift Programming Language book: https://docs.swift.org/swift-book/LanguageGuide/Closures.html If you are looking for a video: [video

u/KarlJay001in r/swift • Recommends

On “What does code(for:"string here") { } do?”

link to this video https://github.com/StewartLynch/IntroductionToClosuresInSwift_Completed