let is not the same as that in ES6.
It is more or like
final in Java. It means the variable (value or reference) cannot be changed once initialization.
let in Swift has stronger semantics, which enable immutability or constant. It means not only the reference cannot be mutable but also the object it refers cannot be mutable.
multiple assignment with tuple:
== is the equal operator, while
=== is identity operator which is used to test wthether two object references both refer to the same object instance.
tuples are compared from left to right.
a ?? b is shorthand for
a != nil ? a! : b
- closed range operator:
- half-open range operator:
Every string is composed of encoding-indepent Unicode characters.
String type is a value type. When you pass a String to a function or assign to a constant/variable, its value is copied.
Actually, it seems to have the similar attribute of immutability as that in Java.
Character can be created from a single-character string literal.
let ch : Character = "1"
Unicode code point is a number for every character in Unicode.
Unicode scalar is any Unicode code point in the range U+0000 ~ U+D7FF or U+E000 ~ U+10FFFF.
The range in U+D800 ~ U+DFFF is for surrogate pair code points.
- escaped special charaters:
\0, \\, \t, \n, \r, \", \'..
- Unicode scalar:
\u00FF without brackets.
Character is not only single Unicode character, it can combine one or more Unicode scalars. Actually, every instance of Swift’s
Character represents a single extended grapheme cluster.
Using extended grapheme clusters makes Swift’s
Characteris so much different from characters in other programming languages.
Due to the representation of Swift
Character, the access and modification ways are special accordingly.
String value has an associated index type,
endIndex properties, which is the half-open range with
No need to use explict
break in each
But if you want the behaviours when missing
break in Java, you can use the
- Interval Matching
- compound cases
- test multiple values with
- value binding