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 Swift 2.0 Enumerations and Optionals Introduction to Enumerations Enums and Objects

Arthur Boilanger
Arthur Boilanger
3,372 Points

Expected Declaration Error

It seems like the code here should be working, but every time I attempt to compile it I'm coming up with the following error: "swift_lint.swift:37:1: error: expected declaration"

Any help is greatly appreciated!

classes.swift
class Point {
    var x: Int
    var y: Int

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

enum Direction {
    case Left 
    case Right
    case Up
    case Down
}


class Robot {
    var location: Point

    init() {
        self.location = Point(x: 0, y: 0)
    }

    func move(direction: Direction) {
        // Enter your code below
       switch direction {
        case Direction.Up: location.y += 1
        case Direction.Down: location.y -= 1
        case Direction.Right: location.x += 1
        case Direction.Left: location.x -= 1
        }
}

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Arthur Boilanger,

Simple fix. You're missing a bracket to close out your function.

class Point { // open1
    var x: Int
    var y: Int

    init(x: Int, y: Int){ // open2
        self.x = x
        self.y = y
    } // close 1
} // close 2

enum Direction { // open3
    case Left 
    case Right
    case Up
    case Down
} // close3


class Robot { // open4
    var location: Point

    init() { // open5
        self.location = Point(x: 0, y: 0)
    } // close5

    func move(direction: Direction) { // open6
        // Enter your code below
       switch direction { // open7
        case Direction.Up: location.y += 1
        case Direction.Down: location.y -= 1
        case Direction.Right: location.x += 1
        case Direction.Left: location.x -= 1
        } // close7
    } // close6 <--- missing
} //close4
Arthur Boilanger
Arthur Boilanger
3,372 Points

Ah... I should've known it was going to be something simple. Spent too much time looking at code lately haha.

Thank you!