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 trialChance Robertson
2,975 PointsIn the editor you've been provided with a struct named Location that models a coordinate point using longitude and latit
In the editor you've been provided with a struct named Location that models a coordinate point using longitude and latitude values.
For this task we want to create a class named Business. The class contains two constant stored properties: name of type String and location of type Location.
In the initializer method pass in a name and an instance of Location to set up the instance of Business. Using this initializer, create an instance and assign it to a constant named someBusiness.
What's wrong with my code?
struct Location {
let latitude: Double
let longitude: Double
init(latitude: Double, longitude: Double){
self.latitude = latitude
self.longitude = longitude
}
}
class Business {
let name: String
let location: Location
init(name: String, location: Double) {
self.name = name
self.location = location
}
}
let someBusiness = Business(name: "Chances", location: Location (latitude: 13.1, longitude: 31.3),
1 Answer
Tassia Castro
iOS Development Techdegree Student 9,170 PointsHey,
It was just the type of the parameter 'location'. You declared as Double but you are trying to pass a Location actually.
struct Location {
let latitude: Double
let longitude: Double
init(latitude: Double, longitude: Double){
self.latitude = latitude
self.longitude = longitude
}
}
class Business {
let name: String
let location: Location
init(name: String, location: Location) { // the type here should be Location not Double =)
self.name = name
self.location = location
}
}
let someBusiness = Business(name: "Chances", location: Location(latitude: 13.1, longitude: 31.3))