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 Build a Simple iPhone App with Swift Getting Started with iOS Development Swift Recap Part 2

The code does not work :(

Can someone see what's wrong?

class Point {
    var x: Int
    var y: Int

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

class Machine: Point {

   override init(x:Int, y: Int) {
        super.init(x: x, y: y)


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

class Robot: Machine {

   override func move(_ direction: String) {
        if direction == "up"{
        if direction == "down"{
        if direction == "left"{
        if direction == "right"{
            return self.x+=1

1 Answer

Hey Fredrik,

When you subclass something, you have to call the parent class' initializer. Also, consider using a switch statement in move:direction. If you don't feel like it, at the very least, you'll want to make sure that you're not returning anything from the function.