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

Need help not sure how to figure out the wording

func move( direction: Direction) { // Enter your code below switch(direction) { case Direction.up: location.y += 1

    case Direction.down: location.y -= 1

    case Direction.left: location.x -= 1

    case Direction.right: location.x += 1

    }}}
test.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.left: location.x -= 1

        case Direction.right: location.x += 1

        }}}

4 Answers

Ollie King
Ollie King
10,194 Points

Hi Tim, I believe you've made the tiniest mistake (you'll probably kick yourself once you realise). So after the word "switch" you've put "direction" in parentheses. Remove them and the code should work! - Hope this helps :)

it says now You need to provide an implementation for the move method

Ollie King
Ollie King
10,194 Points

Oh, ok. Would you be able to paste in the code you're now trying to use?

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.left: location.x -= 1

    case Direction.right: location.x += 1

    }}}

This is the code I'm using now

Ollie King
Ollie King
10,194 Points

Hmmm.. strange..

This is what I have:

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
        }
    }
}

Awesome that work Thanks. I removed the underscore thought was old syntax but didt need to do that Thanks again

Ollie King
Ollie King
10,194 Points

Haha! I didn't know if you had or it was the forum pulling it out of what you copied in.. I've had that happen to me a few times. No worries Tim :)

Happy coding!