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 Recap: Classes

Martel Storm
Martel Storm
4,157 Points

Swift 3 Object-Oriented Quiz True or False Question

This is one of the questions on the quiz at the end of the video collection. I got it wrong and I'd like to know why I missed it.

When creating objects we can only use primitive types (like String, Int, etc) as the types for stored properties True or False

I answered True and got it wrong. Aren't classes and structs considered objects? Then within you put in stored properties such as types... and I guess since you can also store functions. So because you can put in functions does it make the answer to this question False?

Hate missing questions on these quizzes but I love this community~! I feel like I answered my own question but conformation would be nice. Also any tips and tricks for coding/speeding up/motivating myself through these lessons would be awesome!!!

1 Answer

:x: I think you are misunderstanding the question.

The question is saying "When creating objects we can only use primitive types (like String, Int, etc) as the types for stored properties True or False"

It is actually false because when creating objects we can actually have other objects as properties.

Review properties: Properties have a type, like variables and constants do. They store values, but they are part of a object. For example; we can make an object that is called Person and it has three properties: name, age, and favoriteFruit. name is a string (a primitive type), age is an Int (also primitive), and favoriteFood which is a type of a different object, Food. Pretend this class Fruit has two properties: name and isSweet.

:white_check_mark: Doing this is 100% fine Swift, because properties can have a type of a different object.

I hope this makes sense. If you have more questions, please ask below. Thanks!

~Alex