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
AWS Summit Japan 2024と2025の比較/はじめてのKiro、今あなたは岐路に立つ
satoshi256kbyte
0
120
テスト駆動Kaggle
isax1015
1
620
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
320
オンコール⼊⾨〜ページャーが鳴る前に、あなたが備えられること〜 / Before The Pager Rings
yktakaha4
2
990
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
280
ニーリーにおけるプロダクトエンジニア
nealle
0
950
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
500
効率的な開発手段として VRTを活用する
ishkawa
0
160
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
15
5.6k
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
3
1.1k
AI時代のソフトウェア開発を考える(2025/07版) / Agentic Software Engineering Findy 2025-07 Edition
twada
PRO
99
37k
なぜ「共通化」を考え、失敗を繰り返すのか
rinchoku
1
680
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
231
18k
A Tale of Four Properties
chriscoyier
160
23k
Bash Introduction
62gerente
613
210k
Side Projects
sachag
455
42k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Building Applications with DynamoDB
mza
95
6.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.4k
Practical Orchestrator
shlominoach
189
11k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
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Λ؆୯ʹ·ͱΊͯΈ· ͨ͠