Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Davide Rigobon
Davide Rigobon
1,822 Points

This code challenge looks ok for me but when I check it cannot compile it, is it a bug or I'm missing something ?

/Users/DavideRigobon/Desktop/Screenshot 2019-07-17 at 10.00.04.png

objects.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: latitude, longitude: longitude)
        }

    }
}

let someBusiness = Location.Business(name: "Baketsu live", latitude: 11.7, longitude: 3.78)

2 Answers

Daniel Turato
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Daniel Turato
Java Web Development Techdegree Graduate 30,124 Points

You're not meant to provide the longitude or latitude in the init for the business but instead an already established instance of Location. Also, you have your class inside the struct whereas it should be outside the struct. So your code would look like this:

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(name: "test", location: Location(latitude: 2.0, longitude: 2.0))