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.6k
Protocol と Class と SubClass
Protocol で宣言したメソッドが Class / SubClass での動き
Elvis Shi
August 08, 2017
Tweet
Share
More Decks by Elvis Shi
See All by Elvis Shi
How did I build an Open-Source SwiftUI Toast Library
lovee
1
48
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
660
SwiftUIで二重スクロール作ってみた / When I tried to make a dual-scroll-ish view in SwiftUI
lovee
1
240
Observation のあれこれ / A brief introduction about Observation
lovee
3
330
ChatGPT 時代の勉強 / Learning under ChatGPT era
lovee
26
8.2k
属人化しない為の勉強会作り / To make tech meetups with less personal dependencies
lovee
0
270
偏見と妄想で語るスクリプト言語としての Swift / Swift as a Scripting Language
lovee
2
790
danger-swift-kantoku
lovee
1
490
Decimal、正しく使ってる? / Are you using Decimal correctly?
lovee
4
690
Other Decks in Programming
See All in Programming
受け取る人から提供する人になるということ
little_rubyist
0
230
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
EventSourcingの理想と現実
wenas
6
2.3k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
910
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
890
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
280
Jakarta EE meets AI
ivargrimstad
0
140
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Building Applications with DynamoDB
mza
90
6.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Designing for Performance
lara
604
68k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Typedesign – Prime Four
hannesfritz
40
2.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Gamification - CAS2011
davidbonilla
80
5k
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&%ٛڋق⚸ק猳