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 Swift Types Strings

Raza Dar
Raza Dar
iOS Development with Swift Techdegree Student 108 Points

String Concatenation is letting me compile building number & the Street! Is it a bug or a new feature?

let streetAddress = buildingNumber + street Result: "222Khalidia Street"

2 Answers

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

My guess is that you declared the buildingNumber variable differently from the way Pasan did it. In the video, the code looks like this:

let street = "West Street"
let buildingNumber = 222

let streetAddress = buildingNumber + street

This code does not compile because street and buildingAddress are different types. Basically you have text and a number and Swift doesn't know how those should be added together.

My guess is that when you created the buildingNumber constant, you placed quotes around the number:

let buildingNumber = "222"

This would make it so the street and buildingNumber values can be added together because the buildingNumber is a String instead of a number.

Hope that sorts it out for you!

Chron Chern
Chron Chern
314 Points

Thanks for posting and answering this question! Helped a lot!