Slide 1

Slide 1 text

Protocol ͱ Class ͱ SubClass for Otemachi.swift x Kyobashi.swift #01

Slide 2

Slide 2 text

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 { } }

Slide 3

Slide 3 text

খωλ protocol SomeProtocol { func printSelf() } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } protocol SomeProtocol { } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } ≠

Slide 4

Slide 4 text

খωλ 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 ≠

Slide 5

Slide 5 text

খωλ 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 ݺͼग़͠

Slide 6

Slide 6 text

খωλ ⬆ৄ͘͠͸⬆ http://qiita.com/HaNoHito/items/f40bfc1717c1e922a5b0 https://speakerdeck.com/nhamada/swiftniokerumethod-dispatchnituite

Slide 7

Slide 7 text

খωλ 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 ݺͼग़͠

Slide 8

Slide 8 text

ຊ୊ 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

Slide 9

Slide 9 text

ຊ୊ protocol SomeProtocol { func printSelf() } extension SomeProtocol { func printSelf() { print("SomeProtocol") } } class SomeClass: SomeProtocol { }

Slide 10

Slide 10 text

ຊ୊ 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() // ?

Slide 11

Slide 11 text

ຊ୊ 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

Slide 12

Slide 12 text

ຊ୊ 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$

Slide 13

Slide 13 text

ຊ୊ 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 ࣮૷

Slide 14

Slide 14 text

p.printSelf()Ͱ
 SomeSubClass Λ
 ग़ྗͤ͞Δʹ͸ʁ

Slide 15

Slide 15 text

ຊ୊ 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()

Slide 16

Slide 16 text

ຊ୊ 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()

Slide 17

Slide 17 text

ຊ୊ 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()

Slide 18

Slide 18 text

ຊ୊ 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 ຊ࣮૷ʢΦʔόʔϥΠυࡁΈʣݺͼग़͠

Slide 19

Slide 19 text

final ͡Όͳ͍ class ͸ɺ
 σϑΥϧτ࣮૷Λ࢖͏৔߹Ͱ΋ɺ
 PI ͷ࣮૷Λলུͯ͠͸ͳΒͳ͍ɻ Զ ݁࿦

Slide 20

Slide 20 text

⺄⇾獌K15&%ٛڋق⚸ק׿׻猳