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

iOS Object-Oriented Swift Complex Data Structures Methods

Christopher Timbol
Christopher Timbol
1,248 Points

I'm having trouble understanding why the functions points in the struct is returning an array of [Point]?

Shouldn't the method be returning a data type such as String, Double or Int?

3 Answers

Gene Bogdanovich
Gene Bogdanovich
14,618 Points

Because we created Point structure as a blueprint exactly for storing x and y values. So as long as we need to return many x and y pairs, we need to use an array of Point instances. Happy coding!

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I just reviewed that part of the video and no, it needs to return an array of Point. What we're asking it to do is return the points that are within a given range of the point we're currently looking at. You can see a visual representation of this at 10:16 of the video where the red point is the current position. The yellow points are the ones "in range" of the red point. These are the points that are being returned by this method.

Hope this helps! :sparkles:

Will Matthews
Will Matthews
8,127 Points

Another reason it's helpful to return an array of Points rather than just tuples is that you can then carry over our surrounding points method to all of those returned Points.

Imagine if in our game there's some sort of bonus if there's a power up next to any of the points in range. You'd be able to use the method we've already built to test each of those Points in the results.