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

Keep getting errors on my code

I'm on the Object - Oriented Lesson for Swift. My problem has to do with Class & Struct's. I think the problem is that I'm not understanding the last paragraph of what he is asking. It sounds like he wants me to pass an "Instance" as the "location" 's data type within the parameter. He hasn't shown me that in any lesson so far.. So I'm really confused.. Any help would be much appreciated!

objects.swift
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 someLocation = Location(latitude: 34.5, longitude: 23.56)

let someBusiness = Business(name: "LLC", location: someLocation)

1 Answer

The the instance you tried is correct. Th only problem is, your code is that in the initializer saying self.location=Location isn't correct. It should be self.location=location; Here's what the whole code should look like in your way:

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 someLocation = Location(latitude: 34.5, longitude: 23.56)
let someBusiness = Business(name: "LLC", location: someLocation)

Hope that this helped!

If this was any help to you, please, mark as best answer? :-)