Last active
November 27, 2019 14:35
-
-
Save kichiemon/afaf15eedecf5f3472ab to your computer and use it in GitHub Desktop.
[swift]4ステップで実装できるdelegate ref: http://qiita.com/iKichiemon/items/a55b3624e042ea843573
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
| class User { | |
| } |
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
| class MailServer { | |
| } |
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
| class User { | |
| /* | |
| * メール送信の依頼書 | |
| */ | |
| let delegate:MailDelegate? | |
| /* | |
| * ボタンが押された時の処理 | |
| */ | |
| func sendButtonPushed(message: String){ | |
| /* | |
| * 依頼書に書いた機能の実行をお願いする | |
| * 「このメッセージでメールを送信してください!」 | |
| */ | |
| self.delegate?.sendMail(message) | |
| } | |
| } | |
| protocol MailDelegate { | |
| /* | |
| * してほしい処理の名前と引数を書くだけ。 | |
| * 「メール送信お願いします!」 | |
| */ | |
| func sendMail(message: String)->Void | |
| } | |
| /* | |
| * delegateを継承する = 依頼書を受け取る | |
| * 「依頼書を受領しました。なるほど、こういう機能があればいいんですね。実装します!」 | |
| */ | |
| class MailServer: MailDelegate { | |
| var user:User! | |
| init(){ | |
| self.user = User() | |
| // 私(MailServer)が処理の実行を承ります | |
| self.user.delegate = self | |
| } | |
| /* | |
| * メールを送信する処理。ユーザーからの依頼があったときに実行される | |
| * 「あ、このメッセージを送るんですね、わかりました。メール送信します!」 | |
| */ | |
| func sendMail(message: String)->Void{ | |
| // メール送信処理を書く | |
| } | |
| } | |
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 MailDelegate { | |
| } |
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
| class User { | |
| /* | |
| * メール送信の依頼書 | |
| */ | |
| let delegate:MailDelegate? | |
| /* | |
| * ボタンが押された時の処理 | |
| */ | |
| func sendButtonPushed(){ | |
| } | |
| } |
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
| class MailServer { | |
| /* | |
| * メールを送信する処理 | |
| */ | |
| func sendMail(){ | |
| } | |
| } |
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 MailDelegate { | |
| /* | |
| * してほしい処理。 | |
| * 「メール送信お願いします!」 | |
| */ | |
| func sendMail()->Vold | |
| } |
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
| class User { | |
| /* | |
| * メール送信の依頼書 | |
| */ | |
| let delegate:MailDelegate? | |
| /* | |
| * ボタンが押された時の処理 | |
| */ | |
| func sendButtonPushed(message: String){ | |
| /* | |
| * 依頼書に書いた機能の実行をお願いする | |
| * 「このメッセージでメールを送信してください!」 | |
| */ | |
| self.delegate?.sendMail(message) | |
| } | |
| } | |
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
| class MailServer { | |
| /* | |
| * メールを送信する処理 | |
| * 「あ、このメッセージを送るんですね、わかりました。メール送信します!」 | |
| */ | |
| func sendMail(message: String)->Void{ | |
| // メール送信処理を書く | |
| } | |
| } |
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 MailDelegate { | |
| /* | |
| * してほしい処理の名前と引数を書くだけ。 | |
| * 「メール送信お願いします!」 | |
| */ | |
| func sendMail(message: String)->Void | |
| } |
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
| /* | |
| * delegateを継承する = 依頼書を受け取る | |
| * 「依頼書を受領しました。なるほど、こういう機能があればいいんですね。実装します!」 | |
| */ | |
| class MailServer: MailDelegate { | |
| let user:User! | |
| init(){ | |
| // 私(MailServer)が処理の実行を承ります | |
| self.user.delegat = self | |
| } | |
| /* | |
| * メールを送信する処理。ユーザーからの依頼があったときに実行される | |
| * 「あ、このメッセージを送るんですね、わかりました。メール送信します!」 | |
| */ | |
| func sendMail(message: String)->Void{ | |
| // メール送信処理を書く | |
| } | |
| } | |
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
| class User { | |
| /* | |
| * メール送信の依頼書 | |
| */ | |
| let delegate:MailDelegate? | |
| /* | |
| * ボタンが押された時の処理 | |
| */ | |
| func sendButtonPushed(message: String){ | |
| /* | |
| * 依頼書に書いた機能の実行をお願いする | |
| * 「このメッセージでメールを送信してください!」 | |
| */ | |
| self.delegate?.sendMail(message) | |
| } | |
| } | |
| protocol MailDelegate { | |
| /* | |
| * してほしい処理の名前と引数を書くだけ。 | |
| * 「メール送信お願いします!」 | |
| */ | |
| func sendMail(message: String)->Void | |
| } | |
| /* | |
| * delegateを継承する = 依頼書を受け取る | |
| * 「依頼書を受領しました。なるほど、こういう機能があればいいんですね。実装します!」 | |
| */ | |
| class MailServer: MailDelegate { | |
| var user:User! | |
| init(){ | |
| self.user = User() | |
| // 私(MailServer)が処理の実行を承ります | |
| self.user.delegate = self | |
| } | |
| /* | |
| * メールを送信する処理。ユーザーからの依頼があったときに実行される | |
| * 「あ、このメッセージを送るんですね、わかりました。メール送信します!」 | |
| */ | |
| func sendMail(message: String)->Void{ | |
| // メール送信処理を書く | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment