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

duke Beardslee
duke Beardslee
3,361 Points

I need help with the init method

I also don't get what they're asking me to show in the instance.

objects.swift
struct Location {
  let latitude: Double
  let longitude: Double
}
class Buisness {
  let name: String
  let location: Location
  init(latitude: Double, longitude: Double) {
    self.location = Location(latitude: Double, longitude: Double)
  }
}
let someBuisness = 

2 Answers

Heidi Puk Hermann
Heidi Puk Hermann
33,366 Points

Hi, you should remember to include both constants in the init, meaning both name and location. Second, location should be initialised as Location not latitude and longitude.

your init should look like this:

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

now you 'just' have to call ```Business``` correctly ;-)
duke Beardslee
duke Beardslee
3,361 Points

thanks for the help but I'm still having trouble with the instance for someBuisness. Here's my code... struct Location { let latitude: Double let longitude: Double } class Buisness { let name: String let location: Location init(name: String, location: location) { self.location = location self.name = name } } let someBuisness = Buisness(name: "duke", location: 2.3, 2.5)

thanks

Heidi Puk Hermann
Heidi Puk Hermann
33,366 Points

I did contemplate giving you that part of the answer too, but decided against to let let you have a chance to figure it out yourself. What you need to remember, when creating your instance of Business, is that location is of type Location. Thereby needing you to actually create an instance on Location inside your instance of Business. It sound more cryptic than it is :)

You code should look like this:

...
let someBusiness = Business(name: "duke", location: Location(latitude: 2.3, longitude: 2.5))