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 Build a Simple iPhone App with Swift Creating a Data Model Finishing Up Our Model

At 4:00, why does Pasan say, "Now, we need an Int to access it from our array. So we need to cast this into an Int."?

At 4:00, why does Pasan say, "Now, we need an Int to access it from our array. So we need to cast this into an Int."

He goes on to write: Int(randomNumber)

What is "it"? Is "it" the random number generated? If so, why do we need to cast the random number as an Int to access it from our array? What is the action by which we are "accessing" it from our array?

2 Answers

Sam Chaudry
Sam Chaudry
25,519 Points

It's likely he is referring to a data model he will create or is going to create of type array - I have done this course and you will see why this is important. But as a hint the play lists that he has created in the data model will be accessed by a Int, to get the songs for a user. If you look at Swift basics and particularly arrays, you will see that to access a value you get it via an Index. The code usually looks like this:

var names = ["Steve","Mike","Pasan"];

var user = names.objectAtIndexPath(0);

print(user);

//Logs in the console

"Steve"

Simple example on how to access values. But in some cases they just won't be single words, they might be bigger objects like dictionaries. You will see what this means further on you go with this course. Pasan does a great job of helping you get your head around things in this course.

Thanks, Sam!