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

Completely confused! Could you help me to answer this challenge?

Not sure why I am unable to input Double(s) into the instance assigned to someBusiness?

classes.swift
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: "Jamal", location: 20.123444, 22.433333)

4 Answers

David Anton
PLUS
David Anton
Courses Plus Student 30,936 Points

Hey Jamal,

Martin Granger's answer is correct:

All structures have an automatically-generated memberwise initializer, which you can use to initialize the member properties of new structure instances. And must call the initializer with the struct parameters.

The second bug is:

Missing } before the let.

The correct code it:

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.init(name: "Jamal", location: Location(latitude: 20.123444, longitude:22.433333))

Hi Jamal,

I believe your problem is that you've set the location value to a (Double,Double) rather than an instance of Location.

Try this:

let someBusiness = Business(name: "Jamal", location: Location(latitude: 20.123444, longitude: 22.433333))

I really hope it helps you.

Hey Martin! Thanks very much!

Unfortunately this still doesn't work : (

How silly of me! Thanks David!

David Anton
David Anton
Courses Plus Student 30,936 Points

Welcome bro,

Please mark my answer and upvote it if you see it as helped.