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 2.0 Classes Classes with Custom Types

Anton Antonenko
Anton Antonenko
2,127 Points

Spend an hour+ on this. I'm an inermidiate javascript developer so this is really annoying.

this is the error that I'm getting

swift_lint.swift:21:47: error: cannot convert value of type '(Double, Double)' to expected argument type 'Location' let someBusiness = Business("Algo", location: (124235134121223423123123213.12312321312312, 1231253213134324123123412312312312.124212131221)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

when the the struc looks as follows: struct Location { let lat: Double let long: Double }

so it doesnt make since to me why it ant convert my double to type location if the struct of location is of type Double!

classes.swift
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("Algo", location: (124235134121223423123123213.12312321312312, 1231253213134324123123412312312312.124212131221))

1 Answer

Anton, good work until the last lline! Try this:

class Business {
  let name: String
  let location: Location

  init(name: String, location: Location) {
    self.name = name
    self.location = location
  }
}

let someBusiness = Business(name: "Algo", location: Location(latitude: 124.32, longitude: 78.45))

You need the names for each parameter that you pass to the initializers.

Anton Antonenko
Anton Antonenko
2,127 Points

Thank you for you quick response! I can see the the pattern in the syntax now, always pass the name, function, method or struct. Thanks again :)