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 2.0 Basics Swift Types String Manipulation

Masud Mahajna
Masud Mahajna
175 Points

Hi, Actually I don't know what's the problem in my code. I've tried it in Xcode, and it worked! What's the problem?

Hi, Actually I don't know what's the problem in my code. I've tried it in Xcode, and it worked! What's the problem?

strings.swift
// Enter your code below
let name = "Masud."
let greeting = "\("Hi there,") \(name)"

2 Answers

This may have gotten a little complicated, but don't worry! You have the right idea here, but you don't need to interpolate the entire expression (putting it in parentheses), just the variable. Try just the "Hi there " for starts with no parentheses, and place your name variable exactly how you did the first time.

Moderator Edited: Moved response from Comment to Answer

Hi there, Masud! :) Technically your code is okay, but, you don't have to interpolate the string "Hi there," because it is already a string.

Try this:

// Enter your code below
let name = "Masud."
let greeting = "Hi there, \(name)"

Accordingly to Wikipedia: In computer programming, string interpolation or variable interpolation (also variable substitution or variable expansion) is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.

So 'Hi there,' is a string already, you don't need to use string interpolation for it to convert it into a string.