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 Object-Oriented Swift 2.0 Classes Classes with Custom Types

Valeria Ruiz
Valeria Ruiz
948 Points

classes

hi guys, I have been working on this exercise for a while now.

Basically it is saying that I haven't identified "location" but I don't know what else to do to identify it.

Can anyone help me find what is missing in this exercise?

Thanks :)

classes.swift
struct Location {
    let latitude: Double
    let longitude: Double

    class Business{
    let name: String
    let location: Location

    init(x: Double, y: Double){
    self.name = String ("Houston")
    self.location = Location (latitude: x, longitude: y)
    }
    }
}
let someBusiness = "name, \(location)"

1 Answer

Zach Swift
Zach Swift
17,972 Points

Valeria,

Good try.

  1. The struct should be outside of the class. It needs to be it's own thing. Since you have the class nested inside the struct, the compiler isn't seeing the class definition.

  2. You might want to rewatch the video on classes and init. It's a tricky concept to grasp! The purpose of init is to accept arguments the user passes into it, and then set those arguments to the constants. The way you have it now, you are hard coding the values of the arguments inside init, instead of setting them to what is passed in.

  3. Instead of instantiating the object at the bottom, you're actually setting it equal to a string. See below for an example of how I got it to pass

struct Location {
    let latitude: Double
    let longitude: Double
}

class Business{
    let name: String
    let location: Location

    init(name: String, location: Location){
      self.name = name
      self.location = location
    }
}

let loc = Location(latitude: 55.55, longitude: 44.44)
let someBusiness = Business(name:"steve", location: loc)

Good luck!

Valeria Ruiz
Valeria Ruiz
948 Points

Thanks so much this was so helpful!! And yeah, I am going back right now to rematch those videos and check out what else I might have missed and getting in some practice. But your explanation is golden! Thanks so much!! I really appreciate it