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

Wei Jian Kong
Wei Jian Kong
1,429 Points

Code cannot compile

I cannot get my code to compile, can't see what i am doing wrong.

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: "Treehouse", location: Location(latitude: 13.3, longitude: 5.3))
}

1 Answer

Hi there,

I don't think you've closed the Location struct before starting the Business class? Indeed, you've not closed the Business class before using it either.

struct Location {
    let latitude: Double
    let longitude: Double
} // add this to close the struct

class Business {
    let name: String
    let location: Location

    init(name: String, location: Location) {
        self.name = name
        self.location = location
    }
}

// move this line outside of the class
let someBusiness = Business(name: "Treehouse", location: Location(latitude: 13.3, longitude: 5.3))

I hope that helps,

Steve.