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!

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

Jason Oliverson
Jason Oliverson
4,230 Points

Not sure what the error I'm getting means. Can someone point me to what I need to implement?

I've searched other responses, but not code that I try works. It's not getting any errors in xcode either so I'm not sure where I'm going wrong.

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 enum_move(direction: Direction){ 
        switch direction {
        case .up : location.y += 1
        case .down : location.y -= 1
        case .left : location.x -= 1
        case .right : location.x += 1

1 Answer

Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

Almost there. Although your code has no syntax errors and might work in Xcode, it is not what is expected in the challenge and thus by code check.

When starting the challenge, the Robot class already contains the following move method:

func move(_ direction: Direction) { ... }

However, you renamed the move method to enum_move, so code check can not call it.

func enum_move(direction: Direction) { ...  }

Moreover, you removed the underscore _ for the external parameter name. By default, Swift 3 automatically uses the internal parameter name as the external parameter name.

So you had to call this method as follows:

enum_move(direction: .up)

If you don't want the parameter name to be mandatory, you can use the underscore:

func enum_move(_ direction: Direction) { ...  }

This way, you can call this method as follows:


Long story short: don't change the method/variable names and signatures of given code in a challenge ;)

// Change
func enum_move(direction: Direction)
// to
func move(_ direction: Direction) 

Hope that helps :)