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 Complex Data Structures Methods

Rich Valiant
Rich Valiant
2,417 Points

Is Point a type, like Double or Int?

It is used as the return value of the array for the method within the struct. I was a little confused by it because I've never heard it mentioned before as a type.

2 Answers

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Sergio Valentin,

The Swift language has a bunch of standard types already defined for you, such as Int, Double, String, Bool, Float, Array<Element>, etc. (You will soon learn that many things are considered a type in Swift).

However, we can also creates types of our own through the use of Classes, Structures, and Enumerations. This custom data types can be composed of the smaller types and better suit our needs.

For example:

// We might want to make a Person type
class Person {
    name: String = "Steven"
    age: Int = 23
}
var aPerson: Person? 
// here you can make the aPerson variable of type Person, just like you would a String

// We might want to make a Point type
struct Point {
    xCoordinate: Int = 1
    yCoordinate: Int = 3
}
var aPoint: Point? 
var anotherPoint: Point = Point()

Good Luck

Rich Valiant
Rich Valiant
2,417 Points

Thanks Steven Deutsch, this helps a lot.

I like the different examples, they help me wrap my head around the concept. I believe that when the instructor kept saying let's make this variable of Type Point, I somehow only related Int, String, Double and relative examples of text like that as Types. Now I see that essentially (I may still be off here), everything is a Type and can be placed in a variable.

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Sergio Valentin,

Because Swift is an Object Oriented Programming language... (Technically Protocol Oriented Programming) but you'll learn about that later. Essentially everything has a type in Swift because everything is an object. Swift programming is all about creating objects and working with them. All of these objects have a type. A variable or constant.... is just a box/container for an object. You can think of the variable's name and type as a label on that box. The label tells you the name of the box so that you can refer to it. The type label tells you what kind of object(s) are stored in this box.

Hope this helps. Good Luck!

Rich Valiant
Rich Valiant
2,417 Points

Hey Steven Deutsch,

Thanks for this extra insight and further clarification. It is starting to really sync in and definitely conceptually makes sense now!

Alexander Smith
Alexander Smith
10,476 Points

I'm assuming the struct name is Point. When you create a struct it is considered a type just like Int, Bool, Double etc. The word Point is not a type on its own, a struct is a custom made type of whatever you name it

Rich Valiant
Rich Valiant
2,417 Points

Thanks Alexander Smith,

I like the way you defined that "Point" is not a Type of its own, like Int, Bool, Double, etc., but a custom made type through a struct. Slowly wrapping my head around this. I'm going to go back and watch the video again with this perspective in mind and I'm sure it will truly illuminate everything for me.