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

Rohan Thakar
Rohan Thakar
1,579 Points

Im unable to find solution to this problem. can anyone please help me out?

im unable to find solution to this question.how do i assign class to the constatn?

4 Answers

David Papandrew
David Papandrew
8,386 Points

Hi Rohan,

You need to create a new class called Business and setup an initializer that takes a name and location (the latter using the Location type defined in the struct). After you do that, you can create a constant, "someBusiness" and pass in the name and location parameters.

Here is the solution:

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: "Pizza Planet", location: Location(latitude: 10.5, longitude: 44.3))
Rohan Thakar
Rohan Thakar
1,579 Points

Hi David! This is what i had tried ealier however it did not get compiled.

David Papandrew
David Papandrew
8,386 Points

Rohan, I plugged the code above into the exercise and it passed.

Maybe check for any unusual whitespace or misspellings or unclosed parens? Did you check the errors and see any hints there?

Rohan Thakar
Rohan Thakar
1,579 Points

Hey There David, Thanks for your help. I was able to solve it

Rohan Thakar
Rohan Thakar
1,579 Points

Hi Dadvid, im trying to run the below program. there is no error, yet it is not running. Can you please help me out?

struct Tag { let name: String

}

struct Post{ let title: String let author: String let tag: Tag

func description() -> String{

let postDescription = "(firstPost.title) by (firstPost.author). Filed under (firstPost.tag.name)" return postDescription

} } let firstPost = Post(title: "iOS Development", author: " Apple", tag: Tag(name: "swift"))