Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift 2.0 Enumerations and Optionals Introduction to Enumerations Enums and Objects

Enums and object challenge 1

Needing a bit of help not quite understanding what it wants me to do.

"In the editor below you have two objects - a struct named Point and a class named Robot. The Robot stores its location as a point instance and contains a move function.

The task of this challenge is to complete the implementation for move. Move takes a parameter of type Direction which is an enumeration listing the possible movement directions.

When you tell the robot to move up (by specifying Direction.Up as the argument), the y coordinate should increase by 1. Similarly moving down means the y coordinate decreases by 1, moving right means the x coordinate increases by 1 and finally left means x decreases by 1."

3 Answers

Brendan Whiting
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,696 Points

Depending on the direction of the move, you're going to increment or decrement the robot's location x or y coordinate. Let me know if you need more than that.

Ok finally got it thank you :)

Gibson Smiley
Gibson Smiley
1,923 Points

What was the correct code?

Gibson Smiley
Gibson Smiley
1,923 Points

Never mind, I got it:

  switch direction {
        case .Up: location.y += 1
        case .Down: location.y -= 1
        case .Right: location.x += 1
        case .Left: location.x -= 1
Joshua Hardy
Joshua Hardy
17,204 Points
switch direction {
        case .up: location.y += 1
        case .down: location.y -= 1
        case .right: location.x += 1
        case .left: location.x -= 1