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 trialNick Singleton
1,806 PointsI don't understand what this challenge is asking of me? Can someone please explain it to me?
I always have a hard time trying to understand the coding challenges they are asking me becuase of the wording. Please can someone help me out?
struct Location {
let latitude: Double
let longitude: Double
}
class Business {
let name: String
let location: Location
init(name: String, )
}
let someBusiness = self.Business
1 Answer
jcorum
71,830 PointsNick, good start. Now you just need to finish the initializer and then use it:
class Business {
let name: String
let location: Location
init(name: String, location: Location) {
self.name = name
self.location = location
}
}
let someBusiness = Business(name: "Apple", location: Location(latitude: 23.5, longitude: 27.6))
The initializer must make sure that each stored property has a value.
Then, outside the class, you create the constant and use the initializer to create an instance of Business.
There are two tricky parts. First, unlike languages like Java where the initializer and the class have the same name, Swift uses init for the former. But when you use the initializer you type Business.
Also, you need to pass in a location using the struct. You can create it separately, or you can do it in line, like I did above.