Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Kevin Murphy24,380 Points
Swift Closures: Example provided -- animateWithDuration - How does a closure "capture" values?
The treehouse example given for a closure has me quite perplexed. Pasan states:
"The animateWithDuration method is designed as an asynchronous call - when we write our animation code we'll be referring to properties outside the scope of the animations block, but since this is a closure it can capture these references so that when the code is dispatched to the background it still executes properly"
Anyone have a simple closure example for the playground that illustrates all of what Pasan states above? The closures example in apple docs didn't help me much either. In particular, I don't understand how a closure "captures" values. Thanks.