Programming in Swift: Functions and Types · Challenge: Methods | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5429279-programming-in-swift-functions-and-types/lessons/34

Is there an inherited benefit in defining the curveAmount variable in the capture list of the map() function as opposed to defining it outside of the trailing closure prior to calling the map() function on the students array?

Hi! Thanks for your question.

The benefit you get from putting curveAmount in the capture list is that you’re using scope to make your intent clear. If you only mean to use curveAmount within the scope of closure, then putting it in the capture list guarantees that’s the only place you can use it.

Hi Catie,

Thanks so much! That helps my understanding of closures/capture lists/& scope.

1 Like