33
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

swiftの_(underscore)の使い方まとめ

Posted at

数字のフォマット

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")


33
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?