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

My availablePositions instance isn't showing up like an array. Why is that?

//Beginning

struct Point{
    let x: Int
    let y: Int

    init(x: Int, y: Int){
        self.x = x
        self.y = y
    }


    func surroundingPoints(withRange range: Int = 1){

        var results: [Point] = []
        for xCoord in (self.x-range)...(self.x+range){
            for yCoord in (y-range)...(y+range){

                let coordinatePoint = Point(x: xCoord, y: yCoord)
                results.append(coordinatePoint)

            }
        }
    }
}

//at the end of my code...The instance that I'm assuming should be an array

    let availablePositions = position.surroundingPoints(withRange: range)

2 Answers

Yeah sure, you forgot to add this too to function.

-> [Point]

It should be like this:

func surroundingPoints(withRange range: Int = 1) -> [Point] {
  ...
}

Also range and position should be something like this. (position should be of type Point and range should be an Int)

let position = Point(x: 1, y: 2)
let range = 2

You're amazing Ali! Thank you!!

You are welcome

You forgot to add return results at the end of the func

Thanks for the response Ali, even after I add return results after the second bracket in the surroundingPoints method, it gives me an error at that return value and still on the availablePositions instance