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

Daniel Lambrecht
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree
Daniel Lambrecht
iOS Development Techdegree Student 5,302 Points

i need help.. Again

so now ive spend a lot of time trying to get this right. and it still gives me "your code could not be compiled" even though the compiler doesnt return any errors, neither in Xcode or Treehouse...

Honestly, i dont understand why theres even a struct in this assignment.

So i hope one of you guys can explain a bit for me, Appreciate it!

objects.swift
struct Location {
    let latitude: Double
    let longitude: Double

    class Business {
        let name: String
        let location: Location

        init(latitude: Double, longitude: Double) {
            self.name = "Business name"
            self.location = Location(latitude: latitude, longitude: longitude)
        }
    }

}


let someBusiness = Location(latitude: 2.2, longitude: 2.3)

1 Answer

David Papandrew
David Papandrew
8,386 Points

Hi Daniel,

A couple of things: 1) The Business class should not be nested in the Struct. 2) Your Business initializer will have two parameters: name (of type String) and location (of type Location -- the struct) 3) The class properties name and location will be passed the argument values from the initializer

Here's the code:

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: "Acme Hardware", location: Location(latitude: 10, longitude: 10))