From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Make and use closures

Make and use closures

- [Instructor] You'll find closures throughout the APIs, but you may not know how to use them properly. Let's take a basic tour of closures. Download the exercise file and you'll find a project with a playground. Go into the playground and close everything else up so you got plenty of space. And you're going to find a function here and that function is called roundPizzaVolume and it finds the round volume of a pan pizza, but for rectangles it's not going to work. So what I'm going to try to do is make a function within my argument list that has a formula for the area and then I can do any area by just plopping the formula in. I have another function underneath that called anyPizzaVolume. And I'm going to go to the end of that and I'm going to put this in at the end of the argument list. Okay so that will be area. And then I declare instead of a type, I declare all of the types I'm going to use in what would be a function or what's going to end up being our closure. So I'm going to do…

Contents