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.4k
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
460
Other Decks in Programming
See All in Programming
Milestoner
bkuhlmann
1
400
From Spring Boot 2 to Spring Boot 3 with Java 21 and Jakarta EE
ivargrimstad
0
1.1k
Git Lint
bkuhlmann
4
740
PHP8.3の機能を振り返る / Review of PHP 8.3 features
seike460
PRO
1
110
ゆるい個人開発のススメ
kuroppe1819
10
950
try! Swift Tokyo 2024のLT枠に採択されたプロポーザルを出すときに考えていたこと
ski
0
340
Javaエンジニアのための Nodejs/Nuxt3入門
hidekatsu_izuno
0
280
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
120
App Router への移行は「改善」となり得るのか?/ Can migration to App Router be an improvement
takefumiyoshii
8
2.1k
Build with AI 2024 Seoul - 제로부터 시작하는 Flutter with Gemini 생활 - 박제창
itsmedreamwalker
0
200
VSCodeでのDatabricks開発もお勧めしたい/I would also recommend Databricks development with VSCode.
kazumain
0
240
Doctrine ORMでValue Objectを扱う方法4選 #phpstudy / 4 ways to handle Value Objects with Doctrine ORM
77web
4
110
Featured
See All Featured
Designing Experiences People Love
moore
136
23k
How STYLIGHT went responsive
nonsquared
92
4.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
186
16k
Learning to Love Humans: Emotional Interface Design
aarron
266
39k
The Pragmatic Product Professional
lauravandoore
24
5.8k
A Modern Web Designer's Workflow
chriscoyier
688
190k
A better future with KSS
kneath
231
16k
Why Our Code Smells
bkeepers
PRO
331
56k
Become a Pro
speakerdeck
PRO
10
4.5k
Git: the NoSQL Database
bkeepers
PRO
422
63k
How to Ace a Technical Interview
jacobian
272
22k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
115
18k
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Λ؆୯ʹ·ͱΊͯΈ· ͨ͠