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

Jacob Horn
Jacob Horn
9,255 Points

error: missing argument for parameter 'longitude' in call self.location = Location...

I believe I have a call for longitude along with latitude here, am I missing something or is a syntax error tripping me up? Thanks for the help!

classes.swift
struct Location {
    let latitude: Double
    let longitude: Double
}

class Business {
let name: String
let location: Location

init (name: String, latitude: Double, longitude: Double) {

self.name = name
self.location = Location(latitude: Double, longitude: Double)
  }
}

let someBusiness = Business(name: "Apple", latitude: 2.12, longitude: 3.23)

2 Answers

Nathan Tallack
Nathan Tallack
22,160 Points

Close. Take a look at your code with some changes and comments below.

struct Location {
    let latitude: Double
    let longitude: Double
}

class Business {
    let name: String
    let location: Location

    // If you want to pass in the parameter name for the first parameter as you have
    // then you need to give it an external name as it is not used for the very first
    // paramater by default, so i have put name here as an external parameter for you.
    init (name name: String, latitude: Double, longitude: Double) {
        self.name = name
        // Here we are passing in the parameter's from the init function along with the
        // property names for the struct.  So I replaced the parameter type with the
        // names for the parameters that you are using in the init method declaration above.
        self.location = Location(latitude: latitude, longitude: longitude)
    }
}

let someBusiness = Business(name: "Apple", latitude: 2.12, longitude: 3.23)
Nathan Tallack
Nathan Tallack
22,160 Points

To help out, below is an alternate version of your code that is a little easier to understand. :)

struct Location {
    let latitude: Double
    let longitude: Double
}

class Business {
    let name: String
    let location: Location

    init (name: String, lat: Double, long: Double) {
        self.name = name
        self.location = Location(latitude: lat, longitude: long)
    }
}

let someBusiness = Business("Apple", latitude: 2.12, longitude: 3.23)
Jacob Horn
Jacob Horn
9,255 Points

Nathan saves the day! Appreciate the assistance :)