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 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.