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 trial

iOS Object-Oriented Swift Classes in Swift Classes with Custom Types

Arun Kampadathil
Arun Kampadathil
2,429 Points

in 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
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Arun,

Here are your issues:

  1. You are trying to instantiate someBusiness instance inside your class body but it should be in the main body of the program.
  2. When you create the someBusiness instance you are not passing in the values to be initialised (you've hardcoded them in the initialiser).
  3. Your initialiser should take a single instance of Location, not a pair of doubles representing lat and long.
  4. You have an extra space between class and Business



Arun Kampadathil
Arun Kampadathil
2,429 Points

thanks Alex, really appreciate it. explanation is crystal clear