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

Brendan Mauri
Brendan Mauri
932 Points

Not sure how to add a constant to something with two inits, please help :D, thank you in advance

I believe my code is correct except for when i add my constant

objects.swift
struct Location {
  let latitude: Double
  let longitude: Double
}
class Business {
let name: String
let location: Location

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

}
let someBusiness = Business(name: "Oco Industries") (Location: 46.0, 58.2)

3 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

Hi Brendan -

There are a few issues with your code, it begins with initializing your class. You need to initialize the constants you set up in your class. After you get that I believe that you will see how the rest pieces together. If not please feel free to ask me

Thanks

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: "My House", location: Location(latitude: 32.0, longitude: 23.4))
Brendan Mauri
Brendan Mauri
932 Points

Thanks alot for the help man. Im having trouble doing these challenges but this was my best attempt so far. Thanks again

Jeff McDivitt
Jeff McDivitt
23,970 Points

No problem - Some of the challenges are not worded the best which makes it tough for a person learning!! Keep coding and eventually these concepts will be second nature to you :)

is good to teach english grammar but better to apply it to oneself!