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

Eli MBS
Eli MBS
1,158 Points

Classes

Would be very happy if someone could help me with this task :)

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

class Business{
let name: String
let location: Location

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

let someBusiness = Business(name: "Nespresso", location: 10.5)
Kyle Lambert
Kyle Lambert
1,969 Points
struct Location {
    let latitude: Double
    let longitude: Double
}

class Business {
    let name: String
    let location: Location

    init (name: String, location: Location) {  //  pass in an instance of Location
        self.name = name
        self.location = location  //  set location equal to the stored property location, not the struct 'Location'
    }
}

let someBusiness = Business(name: "The Bizz", location: Location(latitude: 35.6, longitude: 77.2))
  //  finally create an instance for Business and pass in Location

Heres the code you're looking for Eli

Hi Eli,

You're almost there! It looks like your problem is in your init() method. You've declared location as type "Double" when this should be a struct Location. You'd also need to assign the value of the variable "location" to self.location rather than "Location"

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

Also,

You'll need to create an instance of Location to pass into the "location" parameter for someBusines instead of a Double value.

let location = Location(latitude:10.0, longitude:23.0 )
let someBusiness = Business(name: "Nespresso", location:location)

I really hope this helps!!!