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

Yong Wha Hong
Yong Wha Hong
1,237 Points

What is wrong with the initializer I wrote?

Why does my posted code not compile?:

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: Double, longitude: Double)


let someBusiness = Business(name: "Starbucks", location: Location(latitude: 43.0, longitude: 43.0))

I get that the following initializer works: init(name: String, location: Location) {

    self.name = name
    self.location = location


But previous videos also seem to show that initializers can take parameters that are stored values from structs outside of the class.

Any help is much appreciated!

Jake Adams
Jake Adams
1,608 Points

Just so I know we're on the same page, can you share the code that isn't working?

1 Answer

Marc Schultz
Marc Schultz
23,356 Points

The tasks contains the following sentence:

In the initializer method pass in a name and an instance of Location to set up the instance of Business.

This means the init method is only allowed to be like:

init(name: String, location: Location)

Your solution is not really wrong, but the internal test methods of the challenge expect the above constructor, so your solution will not be accepted.