Varying Variables and Printing to the Console

String is a type, and we say that the str variable is “an instance of the String type.” Types describe a particular structure for representing data. Swift has many types, which you will meet throughout this book. Each type has specific abilities (what the type can do with data) and limitations (what it cannot do with data). For example, the String type is designed to work with an ordered collection of characters and defines a number of functions to work with that ordered collection of characters.

Recall that str is a variable. That means you can change str’s value. Let’s append an exclamation point to the end of the string to make it a well-punctuated sentence. (Whenever new code is added ...

Get Swift Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.