Swift Basics: String Interpolation
While we ' ve already looked at how to type string values directly into our code , Swift has a powerful feature called String Interpolation . This feature makes your strings incredibly useful by allowing you to inject variables directly inside them . You can place almost any type of variable inside a string . To do this , simply write a backslash \ followed by your variable name wrapped in parentheses (), like this : \ (). Swift var healthPoints = 100 var statusMessage = "You currently have \( healthPoints ) HP." // statusMessage will output: "You currently have 100 HP." You can do this as many times as you want , and even use strings to build other strings ! Swift var battleLog = "Attention player: \( statusMessage )" As we ' ll see shortly , string interpolation isn ' t just limited to placing variables — you can actually execute Swift ...