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

Wesley Jacobs
Wesley Jacobs
5,865 Points

classes with custom types

Help. help. I can't seem to figure out what's wrong with my code. It keeps saying it can't be compiled. The only error I get in Xcode is "expected a separator"

objects.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: "Ross Island", Location(latitude: 12.1, longitude: 12.1)

1 Answer

andren
andren
28,558 Points

There are two issues:

  1. You are missing a closing parenthesis for your Location constructor in the someBusiness constant. That is the cause of the "expected a separator" error.

  2. You are missing the location parameter label.

If you add them like this:

let someBusiness = Business(name: "Ross Island", location: Location(latitude: 12.1, longitude: 12.1))

Then your code will work.