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