Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build an Interactive Story App with Swift Refactoring Our Code Lazy Loading

Wing Sun Cheung
Wing Sun Cheung
4,933 Points

Instead of using a closure, why not use a computed property?

From refactoring our code, howcome Pasan choose to initialize the property using a closure instead of a computed property? Since the closure is executed DURING the object initializing, and we need to add in the lazy keyword, isn't this a roundabout why to achieve what we want to achieve? Why not just have a computed property?

Is it because since computed properties are executed every time you refer to it and closure are executed only once(?), for that reason, we use closures because it would be more efficient to choose the closure path.


1 Answer