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
ISUCON研修おかわり会 講義スライド
arfes0e2b3c
1
450
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
1
5.8k
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
200
チームで開発し事業を加速するための"良い"設計の考え方 @ サポーターズCoLab 2025-07-08
agatan
1
420
データの民主化を支える、透明性のあるデータ利活用への挑戦 2025-06-25 Database Engineering Meetup#7
y_ken
0
360
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
570
Hack Claude Code with Claude Code
choplin
4
2.1k
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
640
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
220
ニーリーにおけるプロダクトエンジニア
nealle
0
840
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
16
11k
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
6
300
Done Done
chrislema
184
16k
The Language of Interfaces
destraynor
158
25k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
20k
Raft: Consensus for Rubyists
vanstee
140
7k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Statistics for Hackers
jakevdp
799
220k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
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Λ؆୯ʹ·ͱΊͯΈ· ͨ͠