LoginSignup
8
8

More than 5 years have passed since last update.

Swiftでコールバックの書き方

Last updated at Posted at 2015-11-29

自分でコールバック関数を使いたくてメモ

宣言

文字列をコールバック関数に渡すメソッドを設定します

func tempFunc(callback: (String) -> Void) {
    callback("callback!!!!")
}

呼び出し

クロージャで指定

tempFunc({ (msg: String) -> Void in
    print(msg)
})

メソッドで指定

func cb(msg:String) {
    print(msg)
}

tempFunc(cb)
8
8
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
8
8