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 2.0 Complex Data Structures Methods

Why does inside the surroundingPointsWithin () method, the xCode recognize X and Y as constants,

declared outside the scope of surroundingPointsWithin () function, X and Y are not passed as parameters to the function. I assume because they are still within the struct, the method has access to them.

Does it mean that any variable or constant (i.e properties) inside a struct, will be automatically available to the methods that are written inside that struct?

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey yousef kazerooni,

You are correct. The properties of the struct can be accessed by the methods of the struct because they are within its scope.

Good Luck!