Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SwiftにおけるMethod Dispatchについて
Search
Naohiro Hamada
February 14, 2017
Programming
0
1.6k
SwiftにおけるMethod Dispatchについて
SwiftのMethod Dispatchについて色々とまとめてみました。
Naohiro Hamada
February 14, 2017
Tweet
Share
More Decks by Naohiro Hamada
See All by Naohiro Hamada
Assertion@Swift
nhamada
0
520
Other Decks in Programming
See All in Programming
AI時代のUIはどこへ行く?
yusukebe
18
8.9k
はじめてのMaterial3 Expressive
ym223
2
740
Azure SRE Agentで運用は楽になるのか?
kkamegawa
0
2.3k
そのAPI、誰のため? Androidライブラリ設計における利用者目線の実践テクニック
mkeeda
2
310
CJK and Unicode From a PHP Committer
youkidearitai
PRO
0
110
ProxyによるWindow間RPC機構の構築
syumai
3
1.2k
Tool Catalog Agent for Bedrock AgentCore Gateway
licux
6
2.5k
機能追加とリーダー業務の類似性
rinchoku
2
1.3k
Processing Gem ベースの、2D レトロゲームエンジンの開発
tokujiros
2
130
🔨 小さなビルドシステムを作る
momeemt
4
680
testingを眺める
matumoto
1
140
プロポーザル駆動学習 / Proposal-Driven Learning
mackey0225
2
1.3k
Featured
See All Featured
Being A Developer After 40
akosma
90
590k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
The Art of Programming - Codeland 2020
erikaheidi
56
13k
RailsConf 2023
tenderlove
30
1.2k
Facilitating Awesome Meetings
lara
55
6.5k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
The Cult of Friendly URLs
andyhume
79
6.6k
Building an army of robots
kneath
306
46k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Agile that works and the tools we love
rasmusluckow
330
21k
Music & Morning Musume
bryan
46
6.8k
Transcript
METHOD DISPATCH@SWIFT SWIFTѪձ VOL.16 N.HAMADA
ࣗݾհ w J04ྺ͘Β͍ w ੲɺNBD04ΞϓϦͷ։ൃΛ͍ͬͯ·ͨ͠ w 2JJUB w IUUQRJJUBDPN)B/P)JUP w
(JU)VC w IUUQTHJUIVCDPNOIBNBEB
ࠓͷ͓ w .FUIPE%JTQBUDIʹ͍ͭͯ w 4XJGUʹ͓͚Δ.FUIPE%JTQBUDIͷ͍Ζ͍Ζ
protocol AlcoholProtocol { } extension AlcoholProtocol { func alcohol()
-> String { return "" } } class TwoBeers { } extension TwoBeers: AlcoholProtocol { func alcohol() -> String { return "" } } let beerServer: AlcoholProtocol = TwoBeers() let myBeer = beerServer.alcohol() print(myBeer)
protocol AlcoholProtocol { } extension AlcoholProtocol { func alcohol()
-> String { return "" } } class TwoBeers { } extension TwoBeers: AlcoholProtocol { func alcohol() -> String { return "" } } let beerServer: AlcoholProtocol = TwoBeers() let myBeer = beerServer.alcohol() print(myBeer) print(myBeer)Ͱग़ྗ͞ΕΔͷ ͱͷͲͬͪʁ
.FUIPE%JTQBUDIͱʁ w ιʔείʔυ্ͷʮϝιουݺͼग़͠ʯͰɺ࣮ࡍʹ ݺͼग़͞ΕΔϝιουɺͲͷϝιουͳͷ͔ʁɹ ΛܾΊΔػߏ extension AlcoholProtocol { func alcohol()
-> String { return "" } } class TwoBeers { } extension TwoBeers: AlcoholProtocol { func alcohol() -> String { return "" } } let beerServer: AlcoholProtocol = TwoBeers() let myBeer = beerServer.alcohol() ʁ
.FUIPE%JTQBUDIͷछྨ 4UBUJD తʹɺϝιουͷݺͼग़͠Λߦ͏ ίϯύΠϧ࣌ 75BCMF ԾςʔϒϧΛͬͯݺͼग़͢ϝιουΛ ܾΊΔ ࣮ߦ࣌ .FTTBHF ϝοηʔδΛૹΔ͜ͱͰɺͲͷϝιουΛ
ݺͿ͔ܾΊΔ ࣮ߦ࣌ 8JUOFTT ࢀরςʔϒϧΛͬͯݺͼग़͢ϝιουΛ ܾΊΔ ࣮ߦ࣌
4UBUJD%JTQBUDI w ίϯύΠϧ࣌ʹɺͲͷϝιο υΛݺͼग़͔͢ɺ͕ܾ·Δ TUSVDU#FFS4FSWFS\ GVODCFFS 4USJOH\ SFUVSO ^ GVODCFFST
4USJOH\ SFUVSO ^ ^ DMBTT#FFS4FSWFS\ pOBMGVODCFFS 4USJOH\ SFUVSO ^ ^
75BCMF w ԾςʔϒϧΛͬͯɺ ࣮ߦ࣌ʹݺͼग़͢ϝιο υΛܾΊΔ w ΫϥεɺԾςʔϒ ϧΛ࣋ͭ class AlcoholServer
{ func alcohol() -> String { return "" } func cheers() -> String { return "" } } class SakeMaker: AlcoholServer { override func alcohol() -> String { return "" } }
75BCMF class AlcoholServer { func alcohol() -> String { return
"" } func cheers() -> String { return "" } } class SakeMaker: AlcoholServer { override func alcohol() -> String { return "" } } "MDPIPM4FSWFS BMDPIPM "MDPIPM4FSWFS DIFFST "MDPIPM4FSWFS 4BLF.BLFS BMDPIPM 4BLF.BLFS DIFFST "MDPIPM4FSWFS
.FTTBHF w .FTTBHFΛͬͯɺͲͷ ϝιουΛݺͼग़͔͢Λ ܾΊΔ w 0CKFDUJWF$Ͱͷϝιου ݺͼग़͠ w 'PVOEBUJPOΛΠϯϙʔ
τ͢Δඞཁ͕͋Δ JNQPSU'PVOEBUJPO DMBTT#FFS4FSWFS\ EZOBNJDGVODBMDPIPM 4USJOH\ SFUVSO ^ EZOBNJDGVODDIFFST 4USJOH\ SFUVSO ^ ^
8JUOFTT w ϓϩτίϧʹ४ڌ͍ͯ͠Δ ߹ʹ࡞ΒΕΔ w ϓϩτίϧͰఆٛ͞Εͨϝ ιουͷݺͼग़͠Λ͢Δͱ ͖ʹΘΕΔ w σϑΥϧτ࣮༻ͷ
8JUOFTT͋Δ QSPUPDPM#FFS\ GVODCFFS 4USJOH ^ QSPUPDPM4BLF\ GVODTBLF 4USJOH ^ TUSVDU"MDPIPM4FSWFS#FFS 4BLF\ GVODCFFS 4USJOH\ SFUVSO ^ GVODTBLF 4USJOH\ SFUVSO ^ ^
ͦ͏͍͑
&YUFOTJPOͲ͏ͳΔ͔ʁ DMBTT#FFS4FSWFS\ GVODBMDPIPM 4USJOH\ SFUVSO ^ ^ FYUFOTJPO#FFS4FSWFS\ GVODDIFFST 4USJOH\
SFUVSO ^ ^
&YUFOTJPOͲ͏ͳΔ͔ʁ DMBTT#FFS4FSWFS\ GVODBMDPIPM 4USJOH\ SFUVSO ^ ^ FYUFOTJPO#FFS4FSWFS\ GVODDIFFST 4USJOH\
SFUVSO ^ ^ w 75BCMF #FFS4FSWFS BMDPIPM #FFS4FSWFS
&YUFOTJPOͲ͏ͳΔ͔ʁ DMBTT#FFS4FSWFS\ GVODBMDPIPM 4USJOH\ SFUVSO ^ ^ FYUFOTJPO#FFS4FSWFS\ GVODDIFFST 4USJOH\
SFUVSO ^ ^ w .FTTBHF w 8JUOFTT w 4UBUJD
&YUFOTJPOͲ͏ͳΔ͔ʁ DMBTT#FFS4FSWFS\ GVODBMDPIPM 4USJOH\ SFUVSO ^ ^ FYUFOTJPO#FFS4FSWFS\ GVODDIFFST 4USJOH\
SFUVSO ^ ^ w .FTTBHF w 8JUOFTT w 4UBUJD
&YUFOTJPOͲ͏ͳΔ͔ʁ DMBTT#FFS4FSWFS\ GVODBMDPIPM 4USJOH\ SFUVSO ^ ^ FYUFOTJPO#FFS4FSWFS\ GVODDIFFST 4USJOH\
SFUVSO ^ ^ w .FTTBHF w 8JUOFTT w 4UBUJD
protocol AlcoholProtocol { } extension AlcoholProtocol { func alcohol()
-> String { return "" } } class TwoBeers { } extension TwoBeers: AlcoholProtocol { func alcohol() -> String { return "" } } let beerServer: AlcoholProtocol = TwoBeers() let myBeer = beerServer.alcohol() print(myBeer) print(myBeer)Ͱग़ྗ͞ΕΔͷ ͱͷͲͬͪʁ
protocol AlcoholProtocol { } extension AlcoholProtocol { func alcohol()
-> String { return "" } } class TwoBeers { } extension TwoBeers: AlcoholProtocol { func alcohol() -> String { return "" } } let beerServer: AlcoholProtocol = TwoBeers() let myBeer = beerServer.alcohol() print(myBeer)
·ͱΊ w 4XJGUͰͷ.FUIPE%JTQBUDIΛ؆୯ʹ·ͱΊͯΈ· ͨ͠