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

Get Swift Quick Syntax Reference 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.