Slide 1

Slide 1 text

ߏ଄తࠩ෼ϥΠϒϥϦ
 ։ൃ࣌ͷ൵ܶتܶ σόοάΛॿ͚Δ

Slide 2

Slide 2 text

ߏ଄తͳࠩ෼ͱ͸Կ͔ ·ͣ͸

Slide 3

Slide 3 text

func testExample1() { let a = Example( key1: "I'm not changed", key2: "I'm deleted" ) let b = Example( key1: "I'm not changed", key2: "I'm inserted" ) XCTAssertEqual(a, b) } Α͋͘ΔTUSVDUͷൺֱ

Slide 4

Slide 4 text

XCTAssertEqual failed: ("Example(key1: "I\'m not changed", key2: "I\'m deleted")") is not equal to ("Example(key1: "I\'m not changed", key2: "I\'m inserted")") - ςετ݁Ռ͸ඇৗʹΘ͔ΓͮΒ͍

Slide 5

Slide 5 text

IUUQHJUIVCDPN,VOJXBL.JSSPS%J⒎,JU ͦ͜Ͱ

Slide 6

Slide 6 text

import MirrorDiffKit func testExample2() { let a = Example( key1: "I'm not changed", key2: "I'm deleted" ) let b = Example( key1: "I'm not changed", key2: "I'm inserted" ) XCTAssertEqual(a, b, diff(between: a, and: b)) } ࣦഊ࣌ͷϝοηʔδʹ
 .JSSPS%J⒎,JUͷEJ⒎Λࢦఆ .JSSPS%J⒎,JUΛJNQPSU

Slide 7

Slide 7 text

struct Example { key1: "I'm not changed" - key2: "I'm deleted" + key2: "I'm inserted" } ͜Ε͕ߏ଄తͳࠩ෼ ͙͢ʹࠩҟ͕Θ͔Γ·͢

Slide 8

Slide 8 text

[ "I'm not changed" "I'm not changed" - "I'm deleted" "I'm not changed" + "I'm inserted" ] ഑ྻͷॱংมߋͳͲ΋
 ߏ଄తͳࠩ෼Ͱ͢ ͜Ε΋ݟ΍͘͢දࣔ͞Ε·͢

Slide 9

Slide 9 text

IUUQHJUIVCDPN,VOJXBL.JSSPS%J⒎,JU ΑΖ͓͘͠ئ͍͠·͢

Slide 10

Slide 10 text

࢓૊Έͷղઆ ࠩ෼ܭࢉͷ

Slide 11

Slide 11 text

let example = Example( key1: "I'm not changed", key2: "I'm deleted" ) let hint = ( subject: Example.self, displayStyle: .struct, children: [ (label: "key1", value: "I'm not changed"), (label: "key2", value: "I'm deleted"), ] ) ߏ଄తͳࠩ෼ͷܭࢉʹ͸ɺ
 ࣍ͷΑ͏ͳΦϒδΣΫτͷ
 ߏ଄ͷώϯτ͕ෆՄܽͰ͢ ΦϒδΣΫτͷܕ ΦϒδΣΫτͷछྨ ϓϩύςΟͷ໊લͱ஋

Slide 12

Slide 12 text

ͦͷػೳΛ୲͏ͷ͕.JSSPS
 ʢඪ४ϥΠϒϥϦͷ"1*Ͱ͢ʣ

Slide 13

Slide 13 text

let example = Example( key1: "I'm not changed", key2: "I'm deleted" ) let mirror = Mirror(reflecting: example) let hint = ( subject: mirror.subjectType, displayStyle: mirror.displayStyle, children: mirror.children ) ௐ΂͍ͨΦϒδΣΫτ͔Β
 .JSSPSΦϒδΣΫτΛ
 ࡞੒͢Δͱɺ ܕ৘ใ΍ΦϒδΣΫτͷछྨɺ
 ϓϩύςΟͷ໊લͱ஋ͳͲΛ
 ೖखͰ͖·͢

Slide 14

Slide 14 text

.JSSPS%J⒎,JU͸ɺ
 ͜ͷ.JSSPSΛ࢖ͬͯ
 ࣮ݱ͞Ε͍ͯ·͢

Slide 15

Slide 15 text

͍ΖΜͳ͜ͱ͕Ͱ͖ͦ͏Ͱ
 ເͷ޿͕Δ"1*Ͱ͢Ͷ

Slide 16

Slide 16 text

تܶ͸͜͜·Ͱͩ

Slide 17

Slide 17 text

΍͹͍OJM͕΍͹͍໰୊ ൵ܶͦͷ

Slide 18

Slide 18 text

struct Example { let any: Any? } let example = Example(any: nil) if let first = Mirror(reflecting: example) .children.first { print(first.value) } ϓϩύςΟΛOJMͰॳظԽ ϓϩύςΟͷ஋ΛݟΔͱɺ
 ઌ΄ͲOJMͰॳظԽͨ͠ͷͰ
 OJMʹͳ͍ͬͯΔ "OZ ͷϓϩύςΟ͕͋ΔTUSVDU .JSSPSΛ࡞੒ͯ͠ɺTUSVDUͷ
 ϓϩύςΟͷώϯτΛೖख

Slide 19

Slide 19 text

struct Example { let any: Any? } let example = Example(any: nil) if let first = Mirror(reflecting: example) .children.first { print(first.value == nil) print(first.value) } GBMTF OJMͰ΋͔֬ΊͯΈΑ͏ ͔͠͠ೖ͍ͬͯΔͷ͸OJMʜ

Slide 20

Slide 20 text

ߟ࡯ฤ ൵͠Έͷ

Slide 21

Slide 21 text

"OZʹ͸
 ͳΜͰ΋ೖΔ ᶃ Int String Bool Any

Slide 22

Slide 22 text

0QUJPOBM΋
 ೖΕΒΕΔ ᶄ Optional Any

Slide 23

Slide 23 text

͢ΔͱOJM΋
 ೖΓ͏Δ ᶄ nil Any

Slide 24

Slide 24 text

ᶄ nil Any == nil GBMTF

Slide 25

Slide 25 text

let x: Any? = nil let wrapper: Any = x // WARNING: Comparing non-optional value of // type 'Any' to nil always returns false print(x == nil) ࣮͸ղઆͨ͠ྫΛίʔυʹ͢Δͱܯࠂ͕ग़Δ ʮ0QUJPOBM͡Όͳ͍஋ͱOJMΛ
 ɹൺֱͯ͠΋ৗʹGBMTFͩΑʯ

Slide 26

Slide 26 text

ͭ·Γɺ"OZʹOJMΛ
 ೖΕͯ͸ͳΒͳ͍ͷͰ͢

Slide 27

Slide 27 text

͔͠͠ɺ.JSSPSͰऔಘͨ͠
 ϓϩύςΟͷ஋ͷܕ͸
 ໰౴ແ༻Ͱ"OZͱ͍͏൵͠Έ ͳͷͰɺϓϩύςΟʹOJMΛ΋ͭ
 ΦϒδΣΫτΛ.JSSPSʹ͔͚Δͱ
 Ϋϥογϡͷةݥ͕͋Γ·͢

Slide 28

Slide 28 text

.JSSPS%J⒎,JUͰ͸͜ͷ໰୊ʹ
 ରॲ͍ͯ͠·͢ͷͰ҆͝৺Λʜ

Slide 29

Slide 29 text

ཁૉ਺ͷUVQMF໰୊ ൵ܶͦͷ

Slide 30

Slide 30 text

enum Example { case zero case one(key: String) case two(key1: String, key2: String) } 4XJGUͰ͸FOVNͷDBTFʹ෇ଐ͢Δ஋ΛఆٛͰ͖·͢ ͜ͷ෇ଐ͢Δ஋͸BTTPDJBUFEWBMVFTͱݺ͹Ε͍ͯ·͢

Slide 31

Slide 31 text

enum Example { case one(key: String) case two(key1: String, key2: String) } func test() { let x1: Example = .one(key: "value") let x2: Example = .two(key1: "value1", key2: "value2") let mirror1 = Mirror(reflecting: x1) let mirror2 = Mirror(reflecting: x2) dump(mirror1.children.first!.value) dump(mirror2.children.first!.value) } ͦΕͧΕΛ.JSSPSʹ͔͚·͢ ͜͜Ͱ͸BTTPDJBUFEWBMVFTͷ
 ཁૉ਺͕ҟͳΔͭͷDBTFΛ
 ఆٛ͠·͢ BTTPDJBUFWBMVFT͸ɺ
 TUSVDUͷϓϩύςΟͱ
 ಉ͡Α͏ʹDIJMESFOͰ
 දݱ͞Ε·͢ ͦΕͧΕͷDIJMESFOΛ
 ֬ೝͯ͠Έ·͠ΐ͏

Slide 32

Slide 32 text

enum Example { case one(key: String) case two(key1: String, key2: String) } func test() { let x1: Example = .one(key: "value") let x2: Example = .two(key1: "value1", key2: "value2") let mirror1 = Mirror(reflecting: x1) let mirror2 = Mirror(reflecting: x2) dump(mirror1.children.first!.value) dump(mirror2.children.first!.value) } BTTPDJBUFEWBMVFT͕
 ͭͷ৔߹ WBMVF ͭͷ৔߹
 
 LFZWBMVF 
 LFZWBMVF
 ܕ͕ҧ͏

Slide 33

Slide 33 text

ߟ࡯ฤ ൵͠Έͷ

Slide 34

Slide 34 text

let y: Any = (number: 123) print(type(of: y)) ܕΛௐ΂ͯΈΔͱ
 *OU ຊ౰͸BTTPDJBUFEWBMVFTͷཁૉ਺͕
 ͍ͭ͘Ͱ͋ΕɺDIJMESFOͷܕ͸UVQMFʹ
 ͔ͨͬͨ͠ͷͰ͸ͱਪଌ ͔͠͠ɺཁૉ਺ͷ͚࣌ͩࣄ৘͕͋ͬͯ
 UVQMFʹͰ͖ͳ͔͔ͬͨ΋͠Εͳ͍ͷͰɺ
 ࢼ͠ʹཁૉ͕ͭͷUVQMFΛ࡞੒ͯ͠ΈΔ UVQMFͰ͸ͳ͍

Slide 35

Slide 35 text

// Error: cannot create a single-element tuple with // an element label let x: (number: Int) = (number: 123)
 
 let y: Any = (number: 123) print(type(of: y)) // Int ࣮͸ɺ4XJGUͷܕͰ͸ཁૉ͕ͭͷUVQMF͸ఆٛͰ͖ͳ͍ ͔͠͠ɺཁૉ਺ͷUVQMFܕ͕
 ࡞Εͳ͍͚ͩͳͷͰɺܕΛ
 "OZʹͯ͠͠·͑͹ཁૉ਺ͷ
 UVQMFΒ͖͠΋ͷΛఆٛͰ͖Δ ͔͠͠ɺఆٛͰ͖ͨͱͯ͠΋ɺ
 ͦͷܕ͸ཁૉͷத਎ͷܕʹ
 ͳΔΑ͏ͩ ͭ·Γɺཁૉ਺ͷUVQMF͸
 ଘࡏͰ͖ͳ͍͜ͱ͕Θ͔Δ

Slide 36

Slide 36 text

ཁૉ਺ͷUVQMFܕ͸ଘࡏͰ͖ͳ͍ͷͰɺ
 ຊདྷ͸UVQMFͰ͋Δ͸ͣͷ
 BTTPDJBUFEWBMVFT͕ɺཁૉ਺ͷ
 ͱ͖ʹத਎͚ͩʹͳΔͷͰͨ͠ʜ

Slide 37

Slide 37 text

.JSSPS%J⒎,JUͰ͸͜ͷ໰୊ʹ
 ରॲ͍ͯ͠·͢ͷͰ҆͝৺Λʜ

Slide 38

Slide 38 text

ΧδϡΞϧʹյΕΔ ൵ܶͦͷ

Slide 39

Slide 39 text

·ͱΊ w .JSSPSͱ͍͏TUSVDUͳͲͷߏ଄Λ
 ௐ΂ΔͨΊͷ"1*͕͋Γ·͢ w ৭ʑͰ͖ͦ͏Ͱເ͕޿͕Γ·͢ w ͔͠͠ɺ͔ͳΓͷͭΒΈ͕͋Γ·͢ͷͰ
 ΍͍ͬͯ͘ࡍʹ͸.JSSPS%J⒎,JUͷ
 ճආྫΛࢀߟʹ͢ΔͱΑ͍Ͱ͠ΐ͏