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 trialJamal Ayton-Brown
1,606 PointsCompletely confused! Could you help me to answer this challenge?
Not sure why I am unable to input Double(s) into the instance assigned to 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: "Jamal", location: 20.123444, 22.433333)
4 Answers
David Anton
Courses Plus Student 30,936 PointsHey Jamal,
Martin Granger's answer is correct:
All structures have an automatically-generated memberwise initializer, which you can use to initialize the member properties of new structure instances. And must call the initializer with the struct parameters.
The second bug is:
Missing } before the let.
The correct code 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.init(name: "Jamal", location: Location(latitude: 20.123444, longitude:22.433333))
Martin Granger
14,521 PointsHi Jamal,
I believe your problem is that you've set the location value to a (Double,Double) rather than an instance of Location.
Try this:
let someBusiness = Business(name: "Jamal", location: Location(latitude: 20.123444, longitude: 22.433333))
I really hope it helps you.
Jamal Ayton-Brown
1,606 PointsHey Martin! Thanks very much!
Unfortunately this still doesn't work : (
Jamal Ayton-Brown
1,606 PointsHow silly of me! Thanks David!
David Anton
Courses Plus Student 30,936 PointsWelcome bro,
Please mark my answer and upvote it if you see it as helped.