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

Equals 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

Hi 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.

I 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.

Is that all the code in the Playground? Can you copy the whole lot in here?

Here is all the code on the Playground page (as per tutorial):

// Binary Operators

let height: Double = 12 // in feet
let width: Double
= 10 // in feet
let area = height * width // area in square feet10

// 1 sq meter = 1 sq foot / 10.764

let areaInMeters = area / 10.764

// Equals Operator (Note: Different from assignment operator)

let string1 = "Hello!"
let string2 = "Hello!"
let string3 = "hello"

I 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 ...

Your code works fine here - I suggest restarting the playground.

I have just done this, hopefully this will sort it out. Thanks for your help!

How did you get on, Amy Hodgson ?

Restarting the playground worked, couldn't work out why it was showing an error, if in doubt turn it off / on again.

Works every time! :wink: :+1: