Join Harrison Ferrone for an in-depth discussion in this video Understand closures, part of Learning Swift 3 for Developers.
- [Tutor] I didn't start using closures,…until I was neck deep in my first heavy networking app,…so I think it's important we cover…some of their basic functionality,…before finishing up our discussion on Swift functions.…A closure is an enclosed set of functionality,…a lot like functions themselves, but with different uses…and a unique syntax structure.…In Swift, a closure is made up of three parts,…the input parameter, the return type and the statements,…that will do any computation inside the executing block.…
Let's make ourselves some room…and put in one more comment,…Understanding Closures.…Let's declare an empty closure first…to see what that looks like.…Start with a new variable.…We're going to call it closureDeclaration.…We're going to give it a type.…It's going to take nothing and return void.…
We're going to initialize it just with a set of curly braces.…Notice that I explicitly typed the empty closure.…You don't have to do this,…but it makes your code easier to read,…when you're trying to match type signatures,…
- Starting a new playground
- Printing to the console
- Declaring variables
- Working with numbers
- Using strings
- Breaking down optionals
- Understanding closures
- Classes vs. structs
- Extensions and protocols
Skill Level Beginner
1. Hello Swift
2. Back to Basics: Variables and Operators
3. Collections, Tuples, and Enumerations
4. Working with Logic Flows
5. Only in Swift: Optionals
6. Functions, Closures, and Associated Types
7. Classes vs. Structs
8. Advanced Topics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
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.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.