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) Types Printing Results

Rob Sproat
Rob Sproat
493 Points

Wait what.... "You were supposed to print 'Learning Swift' but instead you printed 'Learning Swift'

let language = "Swift" var str = Learning" var greeting = "(str) (language)" println (greeting)

And I got an error of: You were supposed to print 'Learning Swift' but instead you printed 'Learning Swift'

Wait what....

I don't know Swift, but this sounds like a type error... like it was expecting you to print "Learning Swift" as the result of your variables evaluating, but instead you told it to print a string whose content was the evaluation of the variables.

Like the difference between println("Learning Swift") and println(greeting)

...?

Hi Rob, the parser is very specific what it is hunting for, quite often to pedantic. Any way there some things with your code worth noting. Your variable str is missing its first set of quotes.

When concancating with your greeting variable it could read:

var greeting = str + language 

( making sure with above you allow a white space at start of the contents of your actual language variable)

Or string interpolation:

var greeting = "\(str) \(language)"

in this example you don't have to have the White space built into variable it's simply allowed for by entering a space between strings.

I'd say it will parse if you use one of the above. Since this question was a long time ago I'm not sure if it wanted concancating or string interpolation. It will want one or the other which would explain why it's parsing without parsing if you get what I mean.

Good luck :)

1 Answer

Meant to post this down here, so for repeat

Hi Rob, the parser is very specific what it is hunting for, quite often to pedantic. Any way there some things with your code worth noting. Your variable str is missing its first set of quotes.

When concancating with your greeting variable it could read:

var greeting = str + language 

( making sure with above you allow a white space at start of the contents of your actual language variable)

Or string interpolation:

var greeting = "\(str) \(language)"

in this example you don't have to have the White space built into variable it's simply allowed for by entering a space between strings.

I'd say it will parse if you use one of the above. Since this question was a long time ago I'm not sure if it wanted concancating or string interpolation. It will want one or the other which would explain why it's parsing without parsing if you get what I mean.