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 trialAmy Hodgson
318 PointsEquals operator - error in xcode
I am working alongside the tutorial in Xcode to make sure I am understanding the concepts presented but have gotten an error, even though I have written exactly what Pasan has shown in the video - here is the code:
let string1 = "Hello!"
let string2 = "Hello!"
let string3 = "hello"
This is the error message:
Playground execution failed:
error: SwiftBasics.playground:9:11: error: consecutive statements on a line must be separated by ';'
let string 2 = "Hello!"
^
;
Is this due to the version of Xcode that I am running (v9.2)?
I am not certain I understand the correction suggested in this instance.
1 Answer
Steve Hunter
57,712 PointsHi Amy,
Your error message suggests you have a space between string
and 2
. If you remove that, it should work.
I edited your code and error output to show what I mean.
Steve.
Amy Hodgson
318 PointsAmy Hodgson
318 PointsI thought that too as I originally did have a space between string and 2 when the error initially occurred but I corrected it so that it doesn't have the space anymore, I've typed it out numerous times as it is within the video and the same error keeps occurring.
The error message seems to suggest to me that I need to write it: let string;2 = "Hello!" but that doesn't make sense either.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsIs that all the code in the Playground? Can you copy the whole lot in here?
Amy Hodgson
318 PointsAmy Hodgson
318 PointsHere is all the code on the Playground page (as per tutorial):
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsI don't recall how Swift treats whitespace - try moving the
= 12
onto the same line as the constant declaration. Might help. (It doesn't explain why the error is showing where it is, though!)Other than that, I can't see anything wrong. I'm just starting XCode on the Mac to see if I can replicate the issue with this.
Back in a sec ...
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsYour code works fine here - I suggest restarting the playground.
Amy Hodgson
318 PointsAmy Hodgson
318 PointsI have just done this, hopefully this will sort it out. Thanks for your help!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsHow did you get on, Amy Hodgson ?
Amy Hodgson
318 PointsAmy Hodgson
318 PointsRestarting the playground worked, couldn't work out why it was showing an error, if in doubt turn it off / on again.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsWorks every time!