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 trialyair bergel
904 PointsCan't pass values to a class
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: "starbucks", location: 11.144, .12.222)
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: "starbucks", location: 11.144, .12.222)
2 Answers
Steve Hunter
57,712 PointsHi there,
You want to create an instance of Location
when you make the someBusiness
instance.
A Location
is made up of a latitude
and longitude
; use the values you have done.
So, rather than this (and remove the dot before the second number):
let someBusiness = Business(name: "starbucks", location: 11.144, 12.222)
Create a Location
:
let aLocation = Location(latitude: 11.144, longitude: 12.222)
But rather than assigning into a constant, just pass it into the Business
class with the required location:
name that the Business
class is expecting:
let someBusiness = Business(name: "Starbucks", location: Location(latitude: 11.144, longitude: 12.222))
I hope that makes sense.
Steve.
yair bergel
904 PointsThank's Steve, I appreciate your help!
Steve Hunter
57,712 PointsNo problem!