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!

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

iOS Object-Oriented Swift Classes and Objects Classes and Their Methods

Ga-eun Kim
Ga-eun Kim
2,558 Points

I don't understand the question

What is the method supposed to do, and what should my code look like?

Jhoan Arango
Jhoan Arango
14,575 Points

Hi, Try showing us your code and or the question.

Jhoan, the question is referring to one of the exercises in the Object-oriented Swift course, there's a link to the exercise on the right of this page, under Related Content heading. The Treehouse UI doesn't make this very clear.

1 Answer

I don't want to just put the answer here, you learn faster if you can figure it out yourself. But start with something like the following function:

func incrementBy(points: Double) {
    // increment width and height here

So, we're passing in a points parameter of type Double and adding that to the width and height stored properties. How do you think we can add points to width and height in the function? Here's a clue:

self.width = self.width + ????

...what should ???? be? Also do the same for height.

Ga-eun Kim
Ga-eun Kim
2,558 Points

Thanks a lot! The 2nd part of the question was a bit confusing, but your answer clarified it :)