Chapter 2: Types & Operations
大綱
Operators with mixed types
Type inference
Characters and strings
Concatenation
Interpolation
Multi-line strings
Type conversion
How computers represent strings
Computers think of strings as a collection of individual characters.
a computer needs to be able to translate a character into the computer’s own language, and it does so by assigning each character a different number. This forms a two-way mapping from character to number that is called a character set.
Unicode
There have been several standards over the years, but the most modern standard is Unicode. It defines the character set mapping that almost all computers use today.




Strings in Swift
Tuples
A whole lot of number types


A peek behind the curtains: Protocols

Key points
Type conversion allows you to convert values of one type into another.
Type conversion is required when using an operator, such as the basic arithmetic operators (+, -, *, /), with mixed types.
Type inference allows you to omit the type when Swift already knows it.
Unicode is the standard for mapping characters to numbers.
A single mapping in Unicode is called a code point.
The Character data type stores single characters. The String data type stores collections of characters, or strings.
You can combine strings by using the addition operator.
You can use string interpolation to build a string in-place.
You can use tuples to group data into a single data type.
Tuples can either be unnamed or named. Their elements are accessed with index numbers for unnamed tuples, or programmer given names for named tuples.
There are many kinds of numeric types with different storage and precision capabilities.
Protocols are how types are organized in Swift.
Last updated