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 Swift Basics (retired) Variables and Constants Variables

Fedor Andreev
Fedor Andreev
11,203 Points

Why is the computer printing the string onto the screen?

var str = "Hello, playground"

And already it's printed onto the screen? How does the computer know you want to print it? You only declared a variable?

In C++, it won't print it onto the screen. You have to tell the computer to print it, using printf or cout<<.

I'm confused, can someone explain this to me? Or is this just a new way of doing things?

Fedor Andreev
Fedor Andreev
11,203 Points

And also, there is no ending declaration after -> playing" Like in C++ you have to use a semi-colon.

Ugh, first lesson and I'm already super confused! haha

1 Answer

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

The reason you see 'Hello, playground' on the screen is because it is showing you the value of the variable, println will print to the console. If you go to view, then open the assistant editor the console will open.