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 trialJames Pacheco
1,810 PointsWhy "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
9,132 PointsThe 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".