Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Swift 2.0 Complex Data Structures Methods

boris said
boris said
3,607 Points

Having errors with return statement

Like said in the title, my return statement is giving an error. The error is 'Cannot convert returns expression of type '[Point]' to return type '[String]'

Here is my code: '''

let x1 = 0 let y1 = 0

let coordinate1: (x: Int, y: Int) = (0, 0)

struct Point { let x: Int let y: Int

func surroundingPointsWith(withRange range: Int = 1) -> [String]{

    var results: [Point] = []

    for xCoord in (x-range)...(x+range) {
        for yCoord in (y-range)...(y+range) {
            let coordinatePoint = Point(x: xCoord, y: yCoord)
            results.append(coordinatePoint)
        }
    }
  return results

}

}

let coordinatePoint = Point(x: 0, y: 0) coordinatePoint.x ''' Thank you in advance for helping

2 Answers

Ivan Kazakov
PLUS
Ivan Kazakov
Courses Plus Student 43,317 Points

Hello Boris. Your function has a return type of an array of Strings (... -> [String]), while you are actually returning an array of Points.

boris said
boris said
3,607 Points

Thank you, this helped greatly