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 trialEddie Aguilar
2,393 Pointsneed some clarification
i am not to sure what the [points] instance is for?? I don't understand what it means. i see it implemented in our other classes we have made and am confused because i do not know what it means. can someone please help and explain
// Enter your code below
struct Point {
let x: Int
let y:Int
///Returs the surrounding points in range of
/// the current one
func points(inrange range: Int = 1) -> [Point] {
var results = [Point]()
let lowerBoundOfXRange = x - range
let upperBoundOfXRange = x + range
let lowerBoundOfYRange = y - range
let upperBoundOfYRange = y + range
for xCoordinate in lowerBoundOfXRange...upperBoundOfXRange {
for yCoordinate in lowerBoundOfYRange...upperBoundOfYRange{
let coordinatePoint = Point(x: xCoordinate, y: yCoordinate)
results.append(coordinatePoint)
}
}
return results
}
}
1 Answer
Chris Stromberg
Courses Plus Student 13,389 PointsThis is an array that holds objects that are of a type "point"
[points]
Its contents would look like this.
var pointOne = Point(x: 2, y: 4)
var pointTwo = Point(x: 3, y: 5)
var pointThree = Point(x: 5, y: 6)
var points : [Point] = [pointOne, pointTwo, pointThree]
This is not unlike when we declare an array of objects of type "Int".
var intArray : [Int] = [1,2,3,4]