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

Paul Je
Paul Je
4,435 Points

Lots of errors

Hey guys,

I found it difficult to know the right syntax (tried various combinations) but I can't seem to remember how to assign which property or class (Point or location) as the way to be able to later return a value after the x or y variable had been changed in each case. Is there a solution that somebody can provide and walk me through in? It feels I can't solve it without some clear cut solution ...

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

class Robot: Machine {

    override func move(direction: String) {
        switch move(direction: String) {
        case move(direction: "Up"): location: Point(x: x, y: y + 1)
        case move(direction: "Down"): Point(x: x, y: y - 1)
        case move(direction: "Left"): Point(x: x - 1, y: y)
        case move(direction: "Right"): Point(x: x + 1, y: y)
        default: break
        }

        override init 


        return location: Point
}

}

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Ok, I know some about Swift... but not enough to really help you. However, I found this post by Steven Deutsch from about a month ago that's really sort of brilliant at explaining it. To the point where even I get it. Take a peek!

https://teamtreehouse.com/community/i-need-help-overriding-this-method

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Steven Deutsch You're welcome! If I could give you the best answer, I would. But you'll be helping me soon enough. I was working on the Swift 2.0 track when my Mac Mini died a horrible, horrible death. When I get it replaced I'm sure I'll have plenty of questions :)

Steven Deutsch
Steven Deutsch
21,046 Points

Sorry to hear about the Mac :( Sounds good, I love helping people learn about Swift. It's such a beautiful, elegant, and modern language. Google is even considering make it a first class language for Android development. I believe Swift is the future of mobile development

Paul Je
Paul Je
4,435 Points

Thanks Steven for your short blurb about the future of Swift and it's potential to stay or grow as a prominent part of computing; I was going to ask this question on Treehouse a few days ago and now I don't have to since it's answered haha

Paul Je
Paul Je
4,435 Points

Awesome!!! Thank you yet again :)