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

Paul Neuhaus
Paul Neuhaus
1,518 Points

Problem with code challenge in Build a Simple iPhone App with Swift 3...

I get the "Bummer" warning when I turn in my answer for this one. It says I have compiler errors, but no errors show in the preview window or in a Swift Playground. What am I doing wrong?

Here's the code challenge...

https://teamtreehouse.com/library/build-a-simple-iphone-app-with-swift-3/getting-started-with-ios-development/swift-recap-part-2

Here's a screenshot...

http://imgur.com/a/dt8wQ

Thanks in advance!

3 Answers

Paul Neuhaus
Paul Neuhaus
1,518 Points

Thanks for your reply, Katherine.

You were right about my Left and Right switch statements being reversed. I thought that might be the problem, but I still get "Bummer".

I did remove " _" in front of direction but that's because the program won't compile with that space-underscore present. The switch statement doesn't read as a switch statement with those extra characters in there. I've tried it both ways. If I use the " _" I get numerous compiler errors. If I do it without, I get the "Bummer" message, but Preview window is empty, giving me no indication of what I've done wrong.

Katherine Ebel
Katherine Ebel
43,799 Points

Hmm...I passed the challenge only changing the left and right case statements, and leaving the argument labels in the function definition. Taking that out could cause problems with how treehouse is testing your code. Adding the _ means you don't need to add the argument label when calling the function. If you take it out you would need to write robot.move(direction: "Up") to call the function. Hopefully I am making sense :) There must be some other syntax error in your code. This code just passed for me...

class Point {
  var x: Int
  var y: Int

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

class Machine {
  var location: Point

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

  func move(_ direction: String) {
    print("Do nothing! I'm a machine!")
  }
}

// Enter your code below
class Robot: Machine {
  override func move(_ direction: String) {
    switch direction {
      case "Up": location.y += 1
      case "Down": location.y -= 1
      case "Left": location.x -= 1
      case "Right": location.x += 1
      default: break
    }
  }
}
Paul Neuhaus
Paul Neuhaus
1,518 Points

I restarted the challenge and used your code. It worked.

I'm baffled as to what went wrong, but now I'm out of the woods.

Thanks, Katherine.

Katherine Ebel
Katherine Ebel
43,799 Points

I notice a couple things in your screen shot. Did you change the method signatures on the move method? When I load the code challenge it shows an ' _' in front of the direction parameter in the move method, but it is not showing on your screen shot. Also.... it looks like you might have your case statements for right and left backwards.You are increasing location.x on left and decreasing on right. I think that is supposed to be the other way...