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 trialJulien Schmitt
2,334 PointsCannot declare instance of business; why?
Hi everyone,
Im trying to declare the instance of business to someBusiness but I guess I did something wrong in the initializer.
Any suggestions?
Thanks,
Julien
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()
1 Answer
Anjali Pasupathy
28,883 PointsYou need to take your Business class out of your Location struct.
Also, when initializing Business, you need to pass in a name parameter and a location parameter.
I hope this helps!
Julien Schmitt
2,334 PointsJulien Schmitt
2,334 PointsHi Anjali,
Took out my business class and added parameters however when declaring the instance and filling it with values, I'm still getting an error. Guess I did something wrong in the init method ?
let SomeBusiness = Business(name: "Amsterdam", location: 2.0)
Anjali Pasupathy
28,883 PointsAnjali Pasupathy
28,883 PointsHello Julien,
You've nearly got it! For location, you need to pass in a Location object, which takes the following form:
Location(latitude: /* PUT LATITUDE HERE */, longitude: /* PUT LONGITUDE HERE */)
I hope this helps!