Slide 1

Slide 1 text

5෼ͰΘ͔Δ SE-0116(id-as-any) by takasek 2016/10/26 potatotips 34 1

Slide 2

Slide 2 text

2

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

Swift Evolution Proposals SE-0116 Import Objective-C id as Swift Any type https://github.com/apple/swift-evolution/ blob/master/proposals/0116-id-as-any.md 4

Slide 5

Slide 5 text

Proposal಺༰ Obj-Cͷidܕ͸ɺSwiftͰ͸ 4 ࠓ·ͰAnyObjectܕͱͯ͠දݱ͞Εͯͨ 4 ͕ɺAnyܕͱͯ͠දݱ͞ΕΔΑ͏ʹͳͬͨ 5

Slide 6

Slide 6 text

6

Slide 7

Slide 7 text

Proposalͷಈػ 7

Slide 8

Slide 8 text

Swift͸ ஋ܕਪ͠ 8

Slide 9

Slide 9 text

ࢀরܕͬͯ ͔ͤͬ͘immutableʹͯ͠΋ ࢀরઌͷ಺༰͕มԽͯ͠ ࣄނΔ͜ͱ͕͋Δ 9

Slide 10

Slide 10 text

ා͍ 10

Slide 11

Slide 11 text

ʮOKɺ஋ܕΛ༻ҙ͠Α͏ʯ 4 String 4 Array 4 Dictionay 4 etc 11

Slide 12

Slide 12 text

! 12

Slide 13

Slide 13 text

Ұํɺ Obj-C͸ id ܕʹΑͬͯଟଶੑΛ࣮ݱͯ͠Δ 4 id ܕ͸લఏͱͯ͠ΦϒδΣΫτܕ 4 Swiftͷ஋ܕ͸ΦϒδΣΫτܕ͡Όͳ͍ 13

Slide 14

Slide 14 text

ͳͷͰ͜Ε·Ͱɺ ϒϦοδՄೳͳܕ͸ɺ ҉໧తʹΦϒδΣΫτܕʹม׵ 4 [AnyObject] ΛNSArrayͱͯ͠ѻ͏ 4 is, as?, as!ʹΑͬͯ஋ܕʹ໭ͤΔ 14

Slide 15

Slide 15 text

ศར 15

Slide 16

Slide 16 text

ศར͚ͩͲɺ ༧ظ͠ͳ͍ಈ͖Λ ى͜͢͜ͱ΋ 16

Slide 17

Slide 17 text

ࠓͷྲྀΕ ʮϠΫβ͗͢Δ͜ͱ͸ࢭΊΑ͏…ʯ SE-0072: ɹ໌ࣔతʹasͨ͠৔߹ʹ͔͠ ɹม׵Ͱ͖ͳ͍Α͏ʹ͠Α͏ʢ࣮૷ࡁʣ SE-0083: ɹasͷػೳ͸ܕνΣοΫ͚ͩʹͯ͠ɺ ɹಈతΩϟετ͸Ͱ͖ͳ͍Α͏ʹ͠Α͏ʢະ࣮૷ʣ 17

Slide 18

Slide 18 text

ͦ͏͜͏ͯͨ͠Β Swift3Ͱ͸ Foundation͕ ஋ܕΛશ໘తʹ࠾༻ 18

Slide 19

Slide 19 text

ʮDarwin(OS X)΋ଞϓϥοτϑΥʔϜ΋ ɹมΘΒͳ͍ΠϯλϑΣʔεΛʂʯ 19

Slide 20

Slide 20 text

ʮAnyObject(Obj-Cͷ౎߹)ʹ ɹҾ͖ͣΒΕͯΔ৔߹͡Όͳ͍ʯ 20

Slide 21

Slide 21 text

ϒϦοδՄೳͳܕͳΒ ΦϒδΣΫτܕʹม׵ʁ 21

Slide 22

Slide 22 text

؁͍ 22

Slide 23

Slide 23 text

͢΂ͯͷ஋ܕΛ ΦϒδΣΫτܕʹ ม׵Ͱ͖ΔΑ͏ʹʂ 23

Slide 24

Slide 24 text

ͦ͏͢Ε͹ Foundation͔Β AnyObject (ΦϒδΣΫτܕ΁ͷґଘ)Λ ഉআͰ͖Δʂ 24

Slide 25

Slide 25 text

ͱ͍͏Θ͚Ͱ 25

Slide 26

Slide 26 text

Swiftͷ஋ܕ → Obj-Cͷidܕ 4 universal bridging conversionΛ৽ن࣮૷ Obj-Cͷidܕ → Swiftͷ஋ܕ 4 طଘͷambivalent dynamic castingΛ࢖͏ 4 ͭ·Γ is , as? , as! AnyHashableϓϩτίϧΛ৽ن࣮૷ 4 Dictionary΍SetͷΩʔͰ࢖͏༻ɻ 4 ΦϒδΣΫτܕͳΒඞͣHashable͚ͩͬͨͲɺ ɹ ஋ܕ͕Hashableͱ͸ݶΒͳ͍ͷͰɻ 26

Slide 27

Slide 27 text

ৄࡉઃܭ 27

Slide 28

Slide 28 text

Any→AnyObjectͷϒϦοδ͸ɺ classes 4 ࢀরܕͳͷͰɺͦͷ·Μ·࢖͑Δ Bridged value types (String, Array, Dictionary, Set, etcͷ͜ͱ) 4 طଘͷ _ObjectiveCBridgeable ϓϩτίϧΛྲྀ༻ 4 SE-0116Ͱ͸ϊʔλον 4 ʢ͚Ͳɺকདྷతʹ͸΋ͬͱଟ͘ͷܕΛbridgeableʹ͍ͨ͠ʣ ͦͷଞͷ஋ܕ 4 immutableͳclassͰboxing͢Δ 4 ݩͷ஋ܕʹ໭ͤΔͳΒɺ಺෦࣮૷Λ֎ʹݟͤΔඞཁ͸ͳ͍ 28

Slide 29

Slide 29 text

஫ҙ఺ !AnyObjectܕ͕ഇࢭ͞Εͨ !Anyܕ͕ΦϒδΣΫτܕʹͳͬͨ 29

Slide 30

Slide 30 text

஫ҙ఺ !AnyObjectܕ͕ഇࢭ͞Εͨ !Anyܕ͕ΦϒδΣΫτܕʹͳͬͨ !AnyܕˠAnyObjectܕ΁ͷ ɹbridge͕׬උ͞Εͨ 30

Slide 31

Slide 31 text

஋ܕ͸ɺ as Any Ͱ͸ͳ͘ as AnyObject ͷλΠϛϯάͰboxing͞ΕΔ let value = 1 as Any let a = value let b = value a as AnyObject === b as AnyObject //false as AnyObject ͷλΠϛϯά͕ҟͳΕ͹ɺ ผͷΦϒδΣΫτͱͯ͠boxing͞ΕΔ 31

Slide 32

Slide 32 text

ΦϒδΣΫτܕʹͳͬͨޙ͸ɺ as Any ͯ͠΋box͕ҡ࣋͞ΕΔ let value = 1 as AnyObject let a = value as Any let b = value as Any a as AnyObject === b as AnyObject //true 32

Slide 33

Slide 33 text

ͱ͍͏Θ͚Ͱ… ΦϒδΣΫτͷಉҰੑ൑ఆ͕ඞཁͳίʔυΛॻ͘ ͱ͖ʹ͸ؾΛ͚ͭΑ͏ʂ FoundationͷAPIͰ͢Βɺ AnyΛҾ਺ʹड͚͓͖ͯͳ͕Βɺ஋ܕΛ౉͢ͱόάΔ΋ͷ͕͋Γ·͢… (Xcode8.0ݱࡏ) 33

Slide 34

Slide 34 text

34

Slide 35

Slide 35 text

Happy Swifting! 35