String, Character
String uses double quotation marks (") as the bounds in Swift:
"Hello!" // greeting‘stypeisString
Character can be initialized from string, as long as it contains only one character:
let"H"// validlet"??"// validlet"abc"// invalid - multiple grapheme clusters
String insertion Value
String interpolation allows an expression to be injected, which can be any value, including strings, integers, floating-point numbers, and other kinds.
The syntax is a slash, followed by a pair of parentheses around the value: \(value) . Any valid expression can appear in parentheses, including function calls.
let number = 5let interpolatedNumber = "\(number)" // string is "5"let fortyTwo = "\(6 * 7)" // string is "42"let example = "This post has \(number) view\(number == 1 ? "" : "s")"// It will output "This post has 5 views" for the above example.// If the variable number had the value 1, it would output "This post has 1 view" instead.
Special characters
- /
Null character
- \
Slash Slash
- \ t
tab character
- \v
Portrait tab
- \ r
Carriage return character
- \ n
Line break
- \”
Double quotes
- \’
Single quotation marks
- \u{n}
Unicode symbols
Like what:
message"Then he said, \"I \u{1F496} you!\""print(message"I ?? you!"
Swift-string, Character