Created
January 16, 2018 04:33
-
-
Save kuju63/b1ceb2f513c258825b565d40b2035c19 to your computer and use it in GitHub Desktop.
Delegateのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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