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
Protocol と Class と SubClass
Search
Elvis Shi
August 08, 2017
Programming
0
1.7k
Protocol と Class と SubClass
Protocol で宣言したメソッドが Class / SubClass での動き
Elvis Shi
August 08, 2017
Tweet
Share
More Decks by Elvis Shi
See All by Elvis Shi
ゼロから始めるPreferenceの実装 / Let's implement Preferences from scratch
lovee
0
78
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
290
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
510
How did I build an Open-Source SwiftUI Toast Library
lovee
1
110
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
1k
SwiftUIで二重スクロール作ってみた / When I tried to make a dual-scroll-ish view in SwiftUI
lovee
1
320
Observation のあれこれ / A brief introduction about Observation
lovee
3
390
ChatGPT 時代の勉強 / Learning under ChatGPT era
lovee
27
8.8k
属人化しない為の勉強会作り / To make tech meetups with less personal dependencies
lovee
0
330
Other Decks in Programming
See All in Programming
未来を拓くAI技術〜エージェント開発とAI駆動開発〜
leveragestech
2
180
CSC305 Summer Lecture 05
javiergs
PRO
0
110
ワープロって実は計算機で
pepepper
2
1.4k
AIレビュアーをスケールさせるには / Scaling AI Reviewers
technuma
2
230
CEDEC 2025 『ゲームにおけるリアルタイム通信への QUIC導入事例の紹介』
segadevtech
3
970
Jakarta EE Core Profile and Helidon - Speed, Simplicity, and AI Integration
ivargrimstad
0
190
TDD 実践ミニトーク
contour_gara
0
140
Understanding Ruby Grammar Through Conflicts
yui_knk
1
120
画像コンペでのベースラインモデルの育て方
tattaka
3
1.8k
Oracle Database Technology Night 92 Database Connection control FAN-AC
oracle4engineer
PRO
1
130
Claude Codeで実装以外の開発フロー、どこまで自動化できるか?失敗と成功
ndadayo
2
1.2k
【第4回】関東Kaggler会「Kaggleは執筆に役立つ」
mipypf
0
750
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.8k
4 Signs Your Business is Dying
shpigford
184
22k
Music & Morning Musume
bryan
46
6.7k
YesSQL, Process and Tooling at Scale
rocio
173
14k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Scaling GitHub
holman
462
140k
The Straight Up "How To Draw Better" Workshop
denniskardys
236
140k
Agile that works and the tools we love
rasmusluckow
329
21k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
Being A Developer After 40
akosma
90
590k
Transcript
Protocol ͱ Class ͱ SubClass for Otemachi.swift x Kyobashi.swift #01
override init() { super.init() emplyedBy = "MAGES. 5pb. Game div"
job = "iOS Developer…?" twitter = "@lovee" qiita = "@lovee" github = "el-hoshino" additionalInfo = "Unity ਏ͍ʘ(^o^)ʗ" class Speaker: Developer { } }
খωλ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } protocol SomeProtocol { } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } ≠
খωλ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { func printSelf() { print("SomeClass") } } let sc = SomeClass() sc.printSelf() // SomeClass (sc as SomeProtocol).printSelf() // SomeClass protocol SomeProtocol { } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { func printSelf() { print("SomeClass") } } let sc = SomeClass() sc.printSelf() // SomeClass (sc as SomeProtocol).printSelf() // SomeProtocol ≠
খωλ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { func printSelf() { print("SomeClass") } } let sc = SomeClass() sc.printSelf() // SomeClass (sc as SomeProtocol).printSelf() // SomeClass protocol SomeProtocol { } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { func printSelf() { print("SomeClass") } } let sc = SomeClass() sc.printSelf() // SomeClass (sc as SomeProtocol).printSelf() // SomeProtocol ≠ Protocol ͷ Interface (PI) એݴ PI σϑΥϧτ࣮ PI ຊ࣮ PI ݺͼग़͠ PI ݺͼग़͠ Protocol ͷ Interface (PI) એݴͳ͠ Protocol ͷ Method (PM) ࣮ Class ͷ Method (CM) ࣮ CM ݺͼग़͠ PM ݺͼग़͠
খωλ ⬆ৄ͘͠⬆ http://qiita.com/HaNoHito/items/f40bfc1717c1e922a5b0 https://speakerdeck.com/nhamada/swiftniokerumethod-dispatchnituite
খωλ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { func printSelf() { print("SomeClass") } } let sc = SomeClass() sc.printSelf() // SomeClass (sc as SomeProtocol).printSelf() // SomeClass protocol SomeProtocol { } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { func printSelf() { print("SomeClass") } } let sc = SomeClass() sc.printSelf() // SomeClass (sc as SomeProtocol).printSelf() // SomeProtocol ≠ Protocol ͷ Interface (PI) એݴ PI σϑΥϧτ࣮ PI ຊ࣮ PI ݺͼग़͠ PI ݺͼग़͠ Protocol ͷ Interface (PI) એݴͳ͠ Protocol ͷ Method (PM) ࣮ Class ͷ Method (CM) ࣮ CM ݺͼग़͠ PM ݺͼग़͠
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { func printSelf() { print("SomeClass") } } let sc = SomeClass() sc.printSelf() // SomeClass (sc as SomeProtocol).printSelf() // SomeClass
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { }
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { } class SomeSubClass: SomeClass { func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) ssc.printSelf() // SomeSubClass p.printSelf() // ?
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { } class SomeSubClass: SomeClass { func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) ssc.printSelf() // SomeSubClass p.printSelf() // ? "ग़ྗʁ AɿSomeProtocol BɿSomeClass CɿSomeSubClass
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { } class SomeSubClass: SomeClass { func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) ssc.printSelf() // SomeSubClass p.printSelf() // SomeProtocol "ग़ྗʁ AɿSomeProtocol# BɿSomeClass$ CɿSomeSubClass$
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { } class SomeSubClass: SomeClass { func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) p.printSelf() // SomeProtocol // == (ssc as SomeClass).printSelf() // == (ssc as SomeProtocol).printSelf() Protocol ͷ Interface (PI) એݴ PI ຊ࣮ͳ͠ʢσϑΥϧτ࣮༻ʣ PI ຊ࣮ʢσϑΥϧτ࣮ʣݺͼग़͠ PI ຊ࣮ʢσϑΥϧτ࣮ʣݺͼग़͠ Class (SomeSubClass) ͷ Method ࣮
p.printSelf()Ͱ SomeSubClass Λ ग़ྗͤ͞Δʹʁ
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { } class SomeSubClass: SomeClass { func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) p.printSelf() // SomeProtocol // == (ssc as SomeClass).printSelf() // == (ssc as SomeProtocol).printSelf()
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { } class SomeSubClass: SomeClass { func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) p.printSelf() // SomeProtocol // == (ssc as SomeClass).printSelf() // == (ssc as SomeProtocol).printSelf() protocol SomeProtocol { func printSelf() } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { } class SomeSubClass: SomeClass { func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) p.printSelf() // SomeProtocol // == (ssc as SomeClass).printSelf() // == (ssc as SomeProtocol).printSelf()
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { } class SomeSubClass: SomeClass { func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) p.printSelf() // SomeProtocol // == (ssc as SomeClass).printSelf() // == (ssc as SomeProtocol).printSelf() protocol SomeProtocol { func printSelf() } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { func printSelf() { (self as SomeProtocol).printSelf() } } class SomeSubClass: SomeClass { override func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) p.printSelf() // SomeSubClass // == (ssc as SomeClass).printSelf() // == (ssc as SomeProtocol).printSelf()
ຊ protocol SomeProtocol { func printSelf() } extension SomeProtocol {
func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { } class SomeSubClass: SomeClass { func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) p.printSelf() // SomeProtocol // == (ssc as SomeClass).printSelf() // == (ssc as SomeProtocol).printSelf() protocol SomeProtocol { func printSelf() } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { func printSelf() { (self as SomeProtocol).printSelf() } } class SomeSubClass: SomeClass { override func printSelf() { print("SomeSubClass") } } class Parent { let someClass: SomeClass // init(someClass: SomeClass) { ... } func printSelf() { someClass.printSelf() } } let ssc = SomeSubClass() let p = Parent(someClass: ssc) p.printSelf() // SomeSubClass // == (ssc as SomeClass).printSelf() // == (ssc as SomeProtocol).printSelf() Protocol ͷ Interface (PI) એݴ PI ຊ࣮ͳ͠ʢσϑΥϧτ࣮༻ʣ Class (SomeSubClass) ͷ Method ࣮ PI ຊ࣮ʢσϑΥϧτ࣮ʣݺͼग़͠ PI ຊ࣮ʢσϑΥϧτ࣮ʣݺͼग़͠ Protocol ͷ Interface (PI) એݴ PI ຊ࣮ʢσϑΥϧτ࣮ྲྀ༻ʣ PI ຊ࣮ʢαϒΫϥεʹΑΔΦʔόʔϥΠυʣ PI ຊ࣮ʢσϑΥϧτ࣮ʣݺͼग़͠ PI ຊ࣮ʢΦʔόʔϥΠυࡁΈʣݺͼग़͠
final ͡Όͳ͍ class ɺ σϑΥϧτ࣮Λ͏߹Ͱɺ PI ͷ࣮Λলུͯ͠ͳΒͳ͍ɻ Զ ݁
⺄⇾獌K15&%ٛڋق⚸ק猳