Skip to content

Instantly share code, notes, and snippets.

@kuju63
Created January 16, 2018 04:33
Show Gist options
  • Select an option

  • Save kuju63/b1ceb2f513c258825b565d40b2035c19 to your computer and use it in GitHub Desktop.

Select an option

Save kuju63/b1ceb2f513c258825b565d40b2035c19 to your computer and use it in GitHub Desktop.
Delegateのサンプル
protocol FooDelegate {
func Foo()
}
class FooApi {
var delegate: FooDelegate
func Someone() {
if delegate != nil {
// delegateのFooメソッドが呼ばれる
delegate?.Foo()
}
}
}
class FooController : UIController , FooDelegate {
func TouchSomeOne() {
let api = FooApi()
// プロパティにdelegateを設定
api.delegate = self
api.Someone()
}
func Foo() {
// 何かの処理
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment