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

Ryan Maneo
Ryan Maneo
4,342 Points

Unclear task

I feel as if the task wasn't explained properly.

classes.swift
struct Location {
    let latitude: Double
    let longitude: Double
}
class Business {
  name: String
  location: Location
init(/* It says "In the init method pass in a name" what does it mean by that?) */ {



}

}


let someBusiness = Business(name: "Some Name") // Confused...

2 Answers

You need to pass in name and location parameters to the init function of the Business class so it knows how to set it up. According to the instructions the name should be a string and the location should be a Location instance.

class Business {
  name: String
  location: Location

  // You pass in the name and location as parameters here
  init(name: String, location: Location)  {
  // You then need to assign these arguments into the properties of the class
  self.name = name // self.name references the class property and name references the passed in argument
  self.location = location // same syntax as above
  }

}
// You then need to create an instance of the business
let someBusiness = Business(name: "MyCo", location: Location(latitude: 100, longitude: 120)) // arbitrary coordinates for Location instance

Hope that helps and let me know if you still have questions.

Ryan Maneo
Ryan Maneo
4,342 Points

I'm sorry I'm still confused... also if thats what I need to do, why didn't he tell me those instructions, as you just did? There was a lot left unsaid on his part :/

Ryan Maneo
Ryan Maneo
4,342 Points

for example, location: Location() I didn't know needed a separate sent of parenthesis. I feel like some of these things are just expected for us to know.

For the location parameter you are passing in a new instance of the Location Struct. To create one you need to instantiate it (hence the ()).