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
Bao Pham
Courses Plus Student 240 PointsPrinting Results: String Interpolation.
So I don't entirely understand this feature of String Interpolation from the "Printing Results" Session.
When he says if I did not have a variable or constant "Declared" like a "String" then I would have to re-write Swift or Objective-C over and over again throughout the project.
That doesn't make sense for me. Even after using String Interpolation and having the constant declared, I don't see any huge advantages. Why? You still could just simply scroll back up to the top and just change the string from a variable or constant and the same effect would be in place. All other codes using the constant or variable will change the string regardless of having a variable or a constant declared. Don't entirely understand the advantages of having and using the String Interpolation when I can simply just do this or that.
1 Answer
Jhoan Arango
14,575 PointsHello Bao: I don’t really understand your question, but seeing that you do not understand string interpolation I will give you an example of what it is.
// Say you declare a variable called “myName” and you give it a value of a string
// “Hello, my name is Bao”.
var myName = "Hello, my name is Bao"
// Now say that somewhere in your code you want to print the value of the variable
// “myName” along with another message, then you do the following.
println("\(myName) and I am learning Swift”)
// This will print “Hello, my name is Bao and I am learning Swift"
This will help you print the value of any variable or constant within a String.
hope that helps