Storing Text in Strings

Strings—blocks of textual data—are another essential data type supported in nearly all programming languages, and Swift’s are really great. Let’s start a new playground to try them out: create the playground with File > New > Playground, and call it StringsPlayground.

Of course, right off the bat, the playground template creates a string for us with var str = "Hello, playground", which evaluates as Hello, playground in the results pane.

Since str is defined with the var keyword, it’s a variable, so let’s change it up a bit. Type the following:

 str = str + ​"!!"

This evaluates as Hello, playground!!, and proves that we can combine strings with the + operator. ...

Get iOS 9 SDK Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.