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 trialArun Kampadathil
2,429 Pointsin xcode I could create an instance of Business, but here in compiler in not executing,
in xcode I could create an instance of Business, but here in compiler in not executing. Will someone assist me?
struct Location {
let latitude: Double
let longitude: Double
}
class Business
{
let name:String
let location:Location
init (name:String = "arun", latitude:Double= 30.2, longitude:Double= 35.7 )
{
self.name = name
self.location = Location(latitude: latitude, longitude: longitude)
}
let someBusiness = Business()
}
2 Answers
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Arun,
Here are your issues:
- You are trying to instantiate someBusiness instance inside your class body but it should be in the main body of the program.
- When you create the someBusiness instance you are not passing in the values to be initialised (you've hardcoded them in the initialiser).
- Your initialiser should take a single instance of Location, not a pair of doubles representing lat and long.
- You have an extra space between
class
andBusiness
Cheers
Alex
Arun Kampadathil
2,429 Pointsthanks Alex, really appreciate it. explanation is crystal clear