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 Object-Oriented Swift Value vs Reference Types Final Exam - Solution

James Pacheco
James Pacheco
1,810 Points

Why "newValue" instead of "area?"

On line 30 of his Xcode window, why does he use "newValue" as a replacement variable in the setter method instead of using "area?"

1 Answer

Chon Long Chiang
Chon Long Chiang
9,132 Points

The setter method will be called when the property, area, is being assigned a new value. When that happens, we want the code to change the sideLength (and automatically change the area as well since its a computed property) So we write: sideLength = sqrt(newValue) All it means is when we assign a new value to a square object, say mySquare, like this: mySquare.area = 100, the 100 here will be accepted as the newValue, and the sideLength would be set to sqrt(100) = 10. If you need a refresh, watch the video in this course under "Properties" : "Setter and Getter Methods".