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

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