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

what I've missed?

I've set the instance up...

classes.swift
struct Location {
    let latitude: Double
    let longitude: Double
    init(latitude:Double,longitude:Double) {
        self.latitude = latitude
        self.longitude = longitude
    }

    class Business {
    let name: String
    let location: Location

    init(latitude:latitude,longitude:longitude) {
    self.name = name
    self.location = Location(latitude:latitude,longitude:longitude)
    }
    }
    let someBusiness = Location(latitude: 1, longitude: 1)
}

4 Answers

Daren Davis
Daren Davis
6,929 Points
struct Location {
    let latitude: Double
    let longitude: Double
}

class Business {
  let name: String
  let location: Location
  init(name: String, newLatitude: Double, newLongitude: Double){
    self.name = name
    self.location = Location(latitude: newLatitude, longitude: newLongitude)
  }
}

let someBusiness = Business(name: "Chucky Cheese", newLatitude: 76.0, newLongitude: 120.0)  // numbers were random

spacing help make your code more clear as well.... good luck..

Daren Davis
Daren Davis
6,929 Points

in the init for business, are you forgetting a stored property? in a Dr. Evil Voice

not really

thks Daren