LoginSignup
82
78

More than 5 years have passed since last update.

【保存版】ググりにくいSwiftの構文の呼び名/用語まとめ

Last updated at Posted at 2015-09-17

とりあえず自分が検索しづらくてイラッとしたやつをまとめました。
今後も追記していきます。

Optionalなオブジェクトをアンラップする !

-> Forced unwrapping

変数宣言の型についてる !

var message: String!

-> Implicitly unwrapped optional type
-> 暗黙的アンラップ

Optionalなオブジェクトのメンバにアクセスするときついてる ?

println(optionalDog?.bark())

-> Optional chaining

if let

if let dog = boy.petDog {
    println(dog.name)
}

-> Optional binding
-> オプショナル束縛
-> if var while let while var などもある

??

let message = json["message"] as? String ?? "no message"

-> Nil coalescing operator
-> Swift double question mark

型チェックの is

-> Type check operator
-> Type checking

キャストの as as? as!

-> Type cast operator
-> Downcasting
-> Force casting (as!)

引数に渡すクロージャが括弧の外に出てる奴

func doSomething(message: String, completion: ()->Void) {
    println("Hello")
    println(message)
    completion()
}

doSomething("Good afternoon") { () -> Void in
    println("Good night")
}
/*
Hello
Good afternoon
Good night
*/

-> Trailing closure

... ..<

for i in 0...5 {
    print(i)
}
/*
012345
*/
or i in 0..<5 {
    print(i)
}
/*
01234
*/

-> Range operator

82
78
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
82
78