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

Geovanny Reyes
Geovanny Reyes
3,876 Points

Has anyone done this code challenge? not sure where to put the switch statement

help appreciated

classes.swift
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! Im a machine!")
    }
}

// Enter your code below

2 Answers

Ryan Doyle
Ryan Doyle
8,587 Points

I have done it, but I don't remember the instructions. I do remember that the switch statement goes within the scope of the "func move { the switch statement goes in here}" because that move function is telling the Machine where to "go."

Steven Parker
Steven Parker
231,236 Points

First, you need to create a Robot class (subclass of Machine). Then inside your new class you will create a move method. The switch (which is optional) would go in that move method.

You can also pass the challenge using only conditional (if) statements and no switch.