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

Juan Coetzer
Juan Coetzer
891 Points

Keep on getting errors

I keep on getting 4 errors:

  1. in my first for loop it says: "Cannot call value of non-function type 'Int'"
  2. at the curly bracket at the end of the first for loop it says: "Expected ',' separator"
  3. at the return statement, it says: "Expected expression in list of expressions"
  4. the curly bracket ending the func gives an error: "Expected ')' in expression list

Don't understand, my code is exactly the same as Pasan's code. Here is my code:

struct Point { let x: Int = 2 let y: Int = 2

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

    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
}

}

1 Answer

Juan Coetzer
Juan Coetzer
891 Points

Never mind, I found my error thank you. /*my first for loop was missing a bracket for xCoord in (x-range...(x+range) should be: */

for xCoord in (x-range)...(x+range)

//my code now works!