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

Calvin Liem
Calvin Liem
3,599 Points

help with challenge

In the editor you've been provided with a struct named Location that models a coordinate point using longitude and latitude values.

For this task we want to create a class named Business. The class contains two constant stored properties: name of type String and location of type Location.

In the initializer method pass in a name and an instance of Location to set up the instance of Business. Using this initializer, create an instance and assign it to a constant named someBusiness.

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 someBusiness = Business(name: "someone", location: (latitude:100.1, longitude:100.5))

how to pass data to type Location?? help me

3 Answers

Greg Kaleka
Greg Kaleka
39,018 Points

Hi Calvin,

You're so close! The problem is that you're trying to call Location's init method without using the struct name. All you need to do is add it:

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 someBusiness = Business(name: "someone", location: Location(latitude:100.1, longitude:100.5))

Sooo close!

let someBusiness = Business(name: "andi", location: Location(latitude: 100.5, longitude: 100.5) )

You need to create a Location object to pass to the Business class, not just pass latitude and longitude.

Calvin Liem
Calvin Liem
3,599 Points

thanksss

very fast response