O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

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

The string type

A string is an ordered collection of characters, such as Hello or Swift. In Swift, the String type represents a string. We have seen several examples of strings in this book, so the following code should look familiar. This code shows how to define two strings:

var stringOne = "Hello" 
var stringTwo = " World" 

We can also create a string using a multiline string literal. The following code shows how we can do that:

var multiLine = """ 
This is a multiline string literal. This shows how we can create a string over multiple lines. 
""" 

Notice that we put three double quotes around the multiline string. We can use quotes in our multiline string to quote specific text. The following code shows how to do this:

var multiLine = """ ...

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