O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7 Strings

In programming, textual 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. Like all strings, it can be thought of as an ordered collection of characters. In reality, Swift strings are not themselves collections, but they do provide a variety of views into their underlying contents that are collections. 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 playground called Strings and add the following new instance of the String type.

Listing 7.1 Hello, playground

import Cocoa

var str = "Hello, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required