O'Reilly logo

Swift Quick Syntax Reference by Matthew Campbell

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

Chapter    6

Strings

A string is a sequence of characters, such as "Hello World!". Strings use the String data type, although you don’t need to specify the data type to use a string, as shown in Listing 6-1.

Listing 6-1. Declaring Strings

var s1 = "Hello World!"

Unicode Characters

Strings can include any Unicode characters. To write single-byte Unicode characters, you must include \x before the two hexadecimal digits. Two-byte Unicode characters are prefixed with \u before four hexadecimal digits, and four-byte Unicode characters have \U written before eight hexadecimal digits.

Listing 6-2 shows an example of using Unicode characters.

Listing 6-2. Unicode Characters

let percentage = "\x{25}"let snowflake = "\u{2744}"let heart = "\u{0001F497}" ...

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