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
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
5
790
XP, Testing and ninja testing
m_seki
3
250
Result型で“失敗”を型にするPHPコードの書き方
kajitack
5
650
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
570
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
Deep Dive into ~/.claude/projects
hiragram
14
2.5k
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
1
18k
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
110
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
640
ふつうの技術スタックでアート作品を作ってみる
akira888
1
850
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
140
PostgreSQLのRow Level SecurityをPHPのORMで扱う Eloquent vs Doctrine #phpcon #track2
77web
2
530
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
A designer walks into a library…
pauljervisheath
207
24k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
GraphQLとの向き合い方2022年版
quramy
49
14k
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.4k
Rebuilding a faster, lazier Slack
samanthasiow
82
9.1k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
6
300
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Speed Design
sergeychernyshev
32
1k
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Λ؆୯ʹ·ͱΊͯΈ· ͨ͠