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
1.7k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Protocol と Class と SubClass
Protocol で宣言したメソッドが Class / SubClass での動き
Elvis Shi
August 08, 2017
More Decks by Elvis Shi
See All by Elvis Shi
@Environment(\.keyPath)那么好我不允许你们不知道! / atEnvironment keyPath is so good and you should know it!
lovee
0
490
ゼロから始めるPreferenceの実装 / Let's implement Preferences from scratch
lovee
0
150
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
390
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
750
How did I build an Open-Source SwiftUI Toast Library
lovee
1
170
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
1.3k
SwiftUIで二重スクロール作ってみた / When I tried to make a dual-scroll-ish view in SwiftUI
lovee
1
380
Observation のあれこれ / A brief introduction about Observation
lovee
3
440
ChatGPT 時代の勉強 / Learning under ChatGPT era
lovee
27
9k
Other Decks in Programming
See All in Programming
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
霧の中の代数的エフェクト
funnyycat
1
390
AIエージェントで 変わるAndroid開発環境
takahirom
2
660
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
0
210
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
380
Performance Engineering for Everyone
elenatanasoiu
0
270
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
110
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
360
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
170
継続モナドとリアクティブプログラミング
yukikurage
3
600
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
130
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
120
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Typedesign – Prime Four
hannesfritz
42
3.1k
Become a Pro
speakerdeck
PRO
31
6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
630
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
220
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
370
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Test your architecture with Archunit
thirion
1
2.3k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
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&%ٛڋق⚸ק猳