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

Margarita Garmutė
Margarita Garmutė
2,136 Points

Can't quite understand about passing methods

In the initializer method pass in a name and an instance of Location to set up the instance of Business. Using this initializer, create an instance and assign it to a constant named someBusiness.

First: why not self.location = Location?

Second: Why we have to create two instances in order to create someBusiness instance?

Thanks a lot!

1 Answer

Magnus Hållberg
Magnus Hållberg
17,232 Points

First, “Location” with a capital “L” will refer to the struct and not the property inside the class.

Second, you create an instance of location inside the Business initializer.

Like this: let someBusiness = Business(name: “The Company”, location: Location(latitude: 45.775, longitude: 78.433))

Margarita Garmutė
Margarita Garmutė
2,136 Points

Thanks, but in the answer
self.location = location, with lower case letter. And not referring to Location. So the question why it's not reffering.

Second: before let someBusiness = Business(name: “The Company”, location: Location(latitude: 45.775, longitude: 78.433))

We have to create instance for Location. So I didn't understand why.

Thanks.