Assignment operators
If the right side of the assignment is a multivariate group, its elements can immediately decompose multiple variables or variables let (x, y) = (1, 2)
x = 1, y = 2 The Swift assignment does not return any value, so the following code is wrong: if x = y {
This sentence error, because x = y does not regret any value
}"+" can also be used for concatenation of strings:"Hello" +"World"
Two character types or one character type and one string type, the addition generates a new string type: let Dog:character = "D"
Let Cow:character = "C"
Let Dogcow = dog + Cow Swift is 8% 2.5//equals 0.5 for floating-point number
comparison OperationNote: Swift also provides two comparators, identity = = = And not identical, to determine whether two objects refer to the same object instance (!==).
Empty merge operatorEmpty merge operator (a??). b) The optional type A is null-judged, if a contains a value to be unpacked, otherwise returns a default value B, which has two conditions:
- Expression A must be of type optional
- The type of the default value B must be consistent with the type of a stored value
The empty merge operator is a short expression of the following code:A! = nil? a!: bcode example: Let Defaultcolorname = "Red"
var userdefinedcolorname:string?
var colornametouse = userdefinedcolorname?? Defaultcolorname
interval operator
The Closed interval operator (A...B) defines a range of values from A to B (including A and b), and b must be greater than a. For index in 1...5 {
println ("\ (index) * 5 = \ (Index * 5)")
The semi-open interval operator semi-open interval operator (a). <B) defines a range from A to B (not including B). Let names = ["Anna", "Alex", "Brian", "Jack"]
Let count = Names.count
For I in 0..<count {
println ("Person \ (i+1) is called \ (Names[i])")
}
Swift Learning notes-2. Basic operators