Upgrade to Pro — share decks privately, control downloads, hide ads and more …

5分でわかるSE-0116(id-as-any)

takasek
October 26, 2016

 5分でわかるSE-0116(id-as-any)

potatotips #34 (http://potatotips.connpass.com/event/41363/) での発表資料です。

SE-0116 (https://github.com/apple/swift-evolution/blob/master/proposals/0116-id-as-any.md) のMotivationの章を重点的に解説。あと、as AnyObjectによるboxingでの注意点についても少し話しました。

takasek

October 26, 2016
Tweet

More Decks by takasek

Other Decks in Programming

Transcript

  1. 2

  2. 3

  3. 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
  4. 6

  5. 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
  6. 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
  7. ஋ܕ͸ɺ 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
  8. ΦϒδΣΫτܕʹͳͬͨޙ͸ɺ 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
  9. 34