数字のフォマット
let paddedDouble = 000123.456
let oneMillion = 1_000_000
let justOverOneMillion = 1_000_000.000_000_1
tupleの使わない値の省略
let (justTheStatusCode, _) = http404Error
println("The status code is \(justTheStatusCode)")
// prints "The status code is 404"
loop時iの省略(loop回数だけ集中したい時)
let base = 3
let power = 10
var answer = 1
for _ in 1...power {
answer *= base
}
println("\(base) to the power of \(power) is \(answer)")
// prints "3 to the power of 10 is 59049"
methodの外部パラメータ名省略(explicit external parameter name)
class Test{
func sayLove(a:String,_ b:String){
println("\(a) love \(b)")
}
}
let test = Test()
test.sayLove("I","U")
default valueがあるfunctionのパラメータの外部パラメータ名省略
func sayLove(a:String,_ b:String = "her"){
println("\(a) love \(b)")
}
sayLove("I","You")