Understand what closures are, and how to use them to encapsulate units of executable code. Get tips on how to write more succinct expressions by using trailing closure syntax and default argument names.
- [Narrator] Functions in Swift are actually…just named closures, closures are blocks…of executable code that can be called inline.…Or stored as a value and passed around in code…to be executed at a later time.…Many programming languages include closures…sometimes called blocks, lambdas or anonymous functions.…I'll show you inline closures first.…I'm starting out with an array of strings.…I'll create a constant to hold names…beginning with the letter "s" and use the filter…method which takes a closure that takes…an element from the array infer it to be…a string in this case and returns a bool.…
The filter method iterates over a sequence…such as an array and applies a true false…conditional check also known as a predicate…to each element in the array and returns…a new array containing only the elements…that pass the predicate in the closure.…I showed you in the previous video…that we can pass a function matching this function type.…This time instead, I'm going to define a closure inline.…By first writing curly braces to enclose the closure and…
Learn how to write code, understand Swift's key concepts and best practices, and strengthen your programming problem-solving skills. Instructor Scott Gardner teaches the fundamentals, so you'll be prepared to develop applications for iOS, macOS, and other platforms. Completing this course will enable you to not only write first-class code, but to think like a Swift developer.
- Creating playgrounds
- Defining variables and constants
- Working with characters and strings
- Working with collections and groups
- Using operators and defining custom operators
- Controlling program flow
- Defining functions and closures
- Working with classes, structures, and enumerations
- Adopting protocols
Skill Level Beginner
1. Get Started
2. Variables and Constants
3. Characters and Strings
4. Collections and Tuples
6. Control Flow
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.