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

David Gourley
David Gourley
3,818 Points

swift basics video course - variables 3 video, variable analogy question please.

Hello there, It's my first day so I'll first ask for patience, thanks. During https://teamtreehouse.com/library/variables-3 I found myself stuck at an analogy and am just seeking some clarification. The analogy of the journal as a variable towards the end of the video around the 13 minute mark. I understand that myjournal is an easier way to ask for a bunch of text. But I wanted to ask if I assign a new str entry to the var myjournal, does it replace all other previous str entries entirely? Thanks in advance, Dave G.

Steven Parker
Steven Parker
231,007 Points

You may have posted this in the wrong category. You can always edit the question and change it.

David Gourley
David Gourley
3,818 Points

I figured it out... Just had to keep watching. It's called concatenation - Adding another entry to the previous entries of myJournal

1 Answer

Simon Di Giovanni
Simon Di Giovanni
8,429 Points

Hi Dave. Good on your for getting started! I know I was a bit overwhelmed with some of this sometimes, but trust me, it's get so much easier the more you learn!

The simplest way i can explain what you're asking, is that there are different 'types' of variables and constants. Some variables can have only 1 piece of information, some can hold multiple pieces of information.

When var myJournal is set, it is a 'String'

'Strings' can only ever be 1 String.

For example -

var myName  = "Simon"

So now, my name is "Simon". It cannot be both "Simon" and "David". BUT. It can CHANGE to "David".

myName = "David"

myName is now "David". It is no longer "Simon"

You will learn later in the courses about constants and variables that can hold multiple data (like "Simon" and "Dave") but no need to worry about that right now.

Hope this helps! Let me know if I can explain further.