// Playground-noun: a place where people can play
import UIKit
// basic operators
// There are three types of operators: monocular operators (such as -a), binary operators (such as a + b), and trinocular operators (a? B: c)
let (x, y) = (20, 30) // decompose tuples
println ("x is \ (x), y is \ (y)")
// Note: Unlike C / OC, in swift = no return value
// Find the remainder a% b a = (b * integer) + sign of remainder b will be ignored
9% -2 // 1
// floating-point remainder
9% 3.3 // 2.4
// nil coalescing operator
var a: Int? = 3
let b: Int = 2
var c = a ?? b // equivalent to c! = nil? c!: b Note that the storage types of b and a must be the same when used. That is, a is of type Int? And b must be of type Int
println ("\ (c)")
// closed interval ...
for i in 0 ... 5 {
println ("\ (i)") // execute 6 times
}
// half-open half-closed interval .. <
for j in 0 .. <5 {
println ("\ (j)") // execute 5 times
}
swift-2-basic operator