Chapter 7. Strings

In programming, text content is represented by strings. You have seen and used strings already. "Hello, playground", for example, is a string that appears at the top of every newly created playground. In this chapter, you will see more of what strings can do.

Working with Strings

In Swift, you create strings with the String type. Create a new macOS playground called Strings and add the following new instance of the String type.

Example 7.1. Hello, playground
import Cocoa

var str = "Hello, playground"
let playground = "Hello, playground"                       "Hello, playground"

You have created a String instance named playground using the string literal syntax, which encloses a sequence of text with quotation marks.

This instance was created ...

Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition 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.