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()
3 Answers
Jhoan Arango
14,575 PointsHello Julien:
The Business class has to be outside the struct that the challenged provided you with. Once you have that done, then you may do the instance of Business.
If you can't seem to pass the challenge with what I just told you, let me know and I will help you even further.
Julien Schmitt
2,334 PointsHi Jhoan,
I just passed it outside. However when I'm assigning Business to the constant, I'm getting an error. I guess location should show latitude and longitude ?
let SomeBusiness = Business(name: "Paris", location: 2.0)
Jhoan Arango
14,575 PointsJulien, that's correct, since in the business initializer you have a parameter that requires a "Location" then you have to pass it an instance of it as an argument.
There are 2 ways you can do it.
let someLocation = Location(latitude: 20, longitude: 20)
let someBusiness = Business(name: "Walmart", location: someLocation)
// Or
let someBusiness = Business(name: "Walmart", location: Location(latitude: 20, longitude: 20) )
Good luck
Julien Schmitt
2,334 PointsThanks!
Didn't know we could call struct as arguments.