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

Swift3.0の破壊的メジャーアップデートの内容をみてみよう

 Swift3.0の破壊的メジャーアップデートの内容をみてみよう

【朝活】iOS開発会議62回目in 株式会社トライフォート
https://www.facebook.com/events/269576500054423/
の発表内容

Swift3.0のアップデート内容を共有しました。

53e2d354b3299d64a54af680865516d5?s=128

Sato Takeshi

May 19, 2016
Tweet

More Decks by Sato Takeshi

Other Decks in Technology

Transcript

  1. ʲே׆ʳiOS։ൃձٞ62ճ໨ in גࣜձࣾτϥΠϑΥʔτ 2016೥5݄19೔ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 1

  2. Swift3.0ͷഁյత ϝδϟʔΞοϓσʔτ ಺༰ΛΈͯΈΑ͏ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 2

  3. Swift3.0͕2016೥ޙ൒ʹϦϦʔε͞ Ε·͢ɻ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 3

  4. Swift2.xͱޓ׵ੑ͸͋Γ·ͤΜɻ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 4

  5. ʘ(^o^)ʗ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 5

  6. ൵͍͠Ͱ͢Ͷ(´ɾТɾʆ) Swiftϓϩάϥϛϯάษڧձ 2016/5/19 6

  7. ٽ͍ͯ͹͔ΓͰ͸͍͚·ͤΜɻ githubͰSwift3.0ͷΞοϓσʔτࢦ਑͕ެ։͞Ε͍ͯ·͢ɻ Swift3.0͕ͲΜͳࢹ఺Ͱมߋ͞Εͯɺ ͲΜͳػೳ͕௥Ճ͞ΕΔͷ͔ΛΈͯɺ ࠓ೥ޙ൒ͷΞοϓσʔτʹඋ͍͑ͨͱࢥ͍·͢ɻ https://github.com/apple/swift-evolution Swiftϓϩάϥϛϯάษڧձ 2016/5/19 7

  8. Swift3.0ͷ໨ඪ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 8

  9. Swiftݴޠͱ։ൃΛ੒ख़͠ɺ҆ఆͤ͞Δ͜ͱɻ ͦͷͨΊʹ͸Swift1ܥͱSwift3.0ͷޓ׵ੑ͕ͳͯ͘΋ߏΘͳ ͍ Ͱ΋Swift3.0ͱSwift3.xʢͦͯ͠Swift4.xҎ্ʣͱͷޓ׵ੑ ͸อͭΑ͏ʹ͍ͨ͠ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 9

  10. Swift3Ͱͷجຊมߋ֓ཁ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 10

  11. APIઃܭΨΠυϥΠϯ Swift͕ΑΓϙϐϡϥʔͳݴޠʹͳΔͨΊͷAPIઃܭΨΠυϥΠϯ Λ·ͱΊ·͢ɻ ৄ͘͠͸API naming and design guidelinesΛݟ·͠ΐ͏ʂ https://swift.org/documentation/api-design-guidelines/ Swiftϓϩάϥϛϯάษڧձ

    2016/5/19 11
  12. Objective-C APIʹ໋໊نଇΛࣗಈతʹม׵ Objective-CͷAPIΛSwift3ʹΠϯϙʔτ͢ΔࡍʹɺίϯύΠϧ͕ Swift3ͷ໋໊نଇʹԊͬͨܗʹࣗಈతʹมߋ͠ɺ੍ޚͰ͖ΔΑ ͏ʹ͢Δɻ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 12

  13. ॏཁͳAPIʹ໋໊نଇΛదԠͤ͞Δ Swiftͷඪ४ϥΠϒϥϦʔ͚ͩͰͳ͘ Foundation΍libdispatchͱ ͍ͬͨॏཁͳAPIϥΠϒϥϦʔʹ΋ϝδϟʔΞοϓσʔτ͞Ε· ͢ɻ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 13

  14. Πϯϙʔτ͞ΕͨObjective-C APIΛΑΓ Swiftyʹม׵ ໋໊نଇͷಋೖ͚ͩͰ͸ͳ͘ɺSwift3Ͱ͸Objective-C ͷAPI͕ ͞ΒʹΑΓྑ͘ಈ࡞͢ΔΑ͏ͳվળΛߦ͍·͢ɻ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 14

  15. ݴޠΛूதͤ͞ߜΓࠐΉ ͍͋·͍ͰΘ͔Γʹ͍͘จ๏Λ࡟আ͠Ұ؏ੑͨ͠޲্ʹ஫ྗ ͠ɺܕγεςϜͷ޲্Λूத͠·͢ɻ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 15

  16. ΫϩεϓϥοτϑΥʔϜ ҆ఆੑ޲্ͤͯ͞ɺඇAppleϓϥοτϑΥʔϜҎ֎Ͱ΋࣮ߦՄ ೳʹ͢Δɻ ଞϓϥοτϑΥʔϜͰ΋ɺSwiftίΞϥΠϒϥϦʔ (Foundation,libdispatch,XCTestͳͲ)Λಈ࡞Մೳʹ͢Δ Linux/x86,FreeBSD, Raspberry Pi, Android, Windows

    etc Swiftϓϩάϥϛϯάษڧձ 2016/5/19 16
  17. ۩ମతͳมߋఏҊ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 17

  18. Swift3.0ͷมߋ಺༰ ໿60ݸ΄Ͳ͋Δɻ 19ݸ΄ͲϐοΫΞοϓʂ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 18

  19. Өڹ౓େͳมߋ5બ • SE-0005 • SE-0044 • SE-0055 • SE-0057 •

    SE-0072 Swiftϓϩάϥϛϯάษڧձ 2016/5/19 19
  20. SE-0005 Objective-C APIΛSwiftʹม׵͢Δ ΑΓྑ͍ํ๏ • Objective-CͷAPIΛSwiftʹΠϯϙʔτ͢Δ͍͞ͷ໋໊نଇΛมߋ͢ΔϚο νϯάํ๏Λهࡌ • Objecitve-CϑϨʔϜϫʔΫΛ࢖༻ͨ͋͠Γͱ͋ΒΏΔطଘͷSwiftίʔυʹ ӨڹΛ༩͑Δɻ

    • ͪͳΈʹFoundation͕Objective-CΛݺΜͰ͍ΔͷͰطଘίʔυશ͕ͯର ৅ʂ • Swift2ͷίʔυ͔ΒSwift3΁ม׵͢ΔϚΠάϨʔγϣϯπʔϧ͕ඞཁ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 20
  21. ྫ͑͹ɺSwift2.2·Ͱ͸͜Μͳίʔυ class UIBezierPath : NSObject, NSCopying, NSCoding { convenience init(ovalInRect:

    CGRect) func moveToPoint(_: CGPoint) func addLineToPoint(_: CGPoint) func addCurveToPoint(_: CGPoint, controlPoint1: CGPoint, controlPoint2: CGPoint) func addQuadCurveToPoint(_: CGPoint, controlPoint: CGPoint) func appendPath(_: UIBezierPath) func bezierPathByReversingPath() -> UIBezierPath func applyTransform(_: CGAffineTransform) var empty: Bool { get } func containsPoint(_: CGPoint) -> Bool func fillWithBlendMode(_: CGBlendMode, alpha: CGFloat) func strokeWithBlendMode(_: CGBlendMode, alpha: CGFloat) func copyWithZone(_: NSZone) -> AnyObject func encodeWithCoder(_: NSCoder) } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 21
  22. Swift3.0͸͜ΜͳίʔυʹͳΔ class UIBezierPath : NSObject, NSCopying, NSCoding { convenience init(ovalIn

    rect: CGRect) func move(to point: CGPoint) func addLine(to point: CGPoint) func addCurve(to endPoint: CGPoint, controlPoint1 controlPoint1: CGPoint, controlPoint2 controlPoint2: CGPoint) func addQuadCurve(to endPoint: CGPoint, controlPoint controlPoint: CGPoint) func append(_ bezierPath: UIBezierPath) func reversing() -> UIBezierPath func apply(_ transform: CGAffineTransform) var isEmpty: Bool { get } func contains(_ point: CGPoint) -> Bool func fill(_ blendMode: CGBlendMode, alpha alpha: CGFloat) func stroke(_ blendMode: CGBlendMode, alpha alpha: CGFloat) func copy(with zone: NSZone = nil) -> AnyObject func encode(with aCoder: NSCoder) } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 22
  23. SE-0044 Objective-C APIΛΑΓSwiftyʹ͢ Δ • CݴޠͷએݴΛΠϯϙʔτ͢Δ͍͞ʹΑΓSwiftΒ͍͠΋ͷʹ ͳΔΑ͏ʹΠϯϙʔτํ๏Λมߋ͢Δ • CݴޠϑϨʔϜϫʔΫΛΠϯϙʔτ͍ͯ͠ΔSwiftϓϩδΣΫ τ͸େن໛ͳӨڹΛड͚ΔɻϚΠάϨʔγϣϯπʔϧͰӨڹ

    ΛܰݮͰ͖·͢ɻ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 23
  24. ྫ͑͹Core Graphics C API: Swift2.2·Ͱ override func drawRect(rect: CGRect) {

    let context: CGContext = UIGraphicsGetCurrentContext()! let toCenter = CGPoint(x: bounds.width/2.0, y: bounds.height/2.0) let angle = CGFloat(M_PI / 16) var transform = CGAffineTransformIdentity for _ in 0..<32 { triangulateRect(bounds, inputTransform: transform, context: context) transform = CGAffineTransformTranslate(transform, toCenter.x, toCenter.y) transform = CGAffineTransformRotate(transform, angle) transform = CGAffineTransformTranslate(transform, -toCenter.x, -toCenter.y) } CGContextSetLineWidth(context, bounds.size.width / 100) CGContextSetGrayStrokeColor(context, 0.5, 1.0) CGContextDrawPath(context, .Stroke) } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 24
  25. ྫ͑͹Core Graphics C API: Swift3.0͔Β override func drawRect(rect: CGRect) {

    let context: CGContext = UIGraphicsGetCurrentContext()! let toCenter = CGPoint(x: bounds.width/2.0, y: bounds.height/2.0) let angle = CGFloat(M_PI / 16) var transform = CGAffineTransform.identity for _ in 0..<32 { triangulateRect(bounds, inputTransform: transform, context: context) transform = transform.translate(toX: toCenter.x, toY: toCenter.y) .rotate(angle: angle) .translate(toX: -toCenter.x, toY: -toCenter.y) } context.lineWidth = bounds.size.width / 100 context.strokeColor = CGColor(gray: 0.5, alpha: 1.0) context.drawPath(mode: .Stroke) } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 25
  26. SE-0055 ҆શͰ͸ͳ͍ϙΠϯλʔͷnullՄೳੑ ΛΦϓγϣφϧܕʹ͢Δ • Objective-CͷϙΠϯλʹ͸ΦϒδΣΫτͰ͋ΕɺඇΦϒδΣΫτͰ͋Ε nullable͔nonnullଐੑΛ͚ͭΒΕΔɻ • Swift͸ඇΦϒδΣΫτͷϙΠϯλUnsafePointer<Int>͕nullʹͳΔ͔Ͳ͏ ͔ͷ۠ผ͕͚ͭΒΕͳ͍ɻ •

    ͳͷͰɺnullʹͳΔՄೳੑͷ͋ΔϙΠϯλΛΦϓγϣφϧܕʹ͠ UnsafePointer<Int>?ͷΑ͏ʹఆٛΛ͢Δɻ • ͋ΒΏΔϙΠϯλܕ͸ӨڹΛड͚Δ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 26
  27. SE-0057 Objecitive-CʹܰྔδΣωϦΫεΛΠ ϯϙʔτ͢Δ • Objective-CͷܰྔδΣωϦΫεػೳΛಋೖͯ͠ɺίϨΫγϣϯܕΛѻ͏࣌ ͷObjevecive-CͷΫϥεΛSwiftʹΠϯϙʔτͨ͠ࡍʹͦͷ··ͷܕͰΠϯ ϙʔτͰ͖ΔΑ͏ʹ͢Δ • ݱঢ়͸AnyObjectʹͳ͍ͬͯͨɻ •

    NSArray<NSString *> * ΛΠϯϙʔτͨ͠ࡍʹ[String]ʹͳΔΑ͏ʹͳΔɻ • Ҿ਺ͳ͠ͰObjective-CͷίϨΫγϣϯܕΛఆ͍ٛͯ͠Δίʔυ͸ӨڹΛड ͚Δɻ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 27
  28. ӨڹΛड͚Δίʔυ let array: NSArray = ["hello", "world"] // okay, infer

    NSArray<NSString> // old var mutArray = NSMutableArray() // error: need type arguments for NSMutableArray Swiftϓϩάϥϛϯάษڧձ 2016/5/19 28
  29. SE-0072 Swift͔Βͷ҉໧ͷϒϦοδม׵Λ׬ શʹͳ͘͢ • Swift1.2Ͱ҉໧ͷϒϦοδม׵Λͳ͚ͨ͘͠ͲɺObjective-CͷAPIͰ ஫ऍ͕͋Δ৔߹͸ͳͯ͘͠ͳ͔ͬͨɻSwift3ͰͦΕ΋׬શʹফ͠· ͢ɻ • Objective-CͷAPI͸໌ࣔతʹΩϟετ͠ͳͯ͘͸͍͚ͳ͘ͳΓ· ͢ɻ

    • ҉໧ʹΩϟετ͍ͯͨ͠ίʔυ͸asΛ͔ͭͬͯͷΩϟετ͕ඞཁͰ͢ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 29
  30. จ๏ͷมߋ఺ Θ͔Γʹ͍͘จ๏ΛҰ৽͢ΔఏҊ11બ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 30

  31. SE-0002: ؔ਺ఆٛͰͷΧϦʔԽจ๏ͷ࡟আ Θ͔Γʹ͍͘ΜͰ࡟আ // Before: func curried(x: Int)(y: String) ->

    Float { return Float(x) + Float(y)! } // After: func curried(x: Int) -> (String) -> Float { return {(y: String) -> Float in return Float(x) + Float(y)! } } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 31
  32. SE-0003: ؔ਺ͷҾ਺ͰͷvarΛ࡟আ ؔ਺Ҿ਺ͰvarΛఆٛͯ͠Ҿ਺มߋ͕Ͱ͖ͳ͘ͳΔ //for swift2.2 func foo(var i: Int) {

    i += 1 // OK, but the caller cannot observe this mutation. } //for swift3.0 func foo(i: Int) { i += 1 // illegal } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 32
  33. SE-0053: ؔ਺ͷҾ਺Ͱͷ໌ࣔతletΛ ࡟আ ؔ਺ͷҾ਺͸มߋͰ͖ͳ͘ͳΔ func foo(let x: Int) { ...

    }// not work! func foo(x: Int) { ... }// fine! Swiftϓϩάϥϛϯάษڧձ 2016/5/19 33
  34. SE-0004: ++,--ΦϖϨʔλͷ࡟আ CݴޠͰ࢖ΘΕͨ++,--ΦϖϨʔλ͸SwiftͰ͸୅ସखஈ͕๛෋ Ͱɺҙຯ͕ͳ͍ʹ΋͔͔ΘΒͣແ༻ͳޡղΛੜΉॻ͖ํͳͷͰ ࡟আ x += 1 ·ͨ͸ΠϯσοΫεܕͰ x

    = x.successor() ʹมߋ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 34
  35. SE-0007: CݴޠελΠϧͷforจͷ࡟ আ Cݴޠͷforจ[ྫʀfor(var i = 1; i < 10;

    i++ʣ]͸Swiftͬ Ά͘ͳ͍ͷͰ࡟আ for-inจΛ࢖͓͏ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 35
  36. SE-0029: ؔ਺Ҿ਺ΛλϓϧͰද͢จ๏Λ࡟আ ؔ਺ͷҾ਺ΛλϓϧͰ͔͚ΔγϯλοΫεγϡΨʔ͕͋ͬͨΜ ͚ͩͲɺҙຯͳ͍ΜͰ࡟আ͠·͢ ͜ͷॻ͖ํ͕Ͱ͖ͳ͘ͳΔ func foo(a : Int, b

    : Int) {} let x = (1, b: 2) foo(x) Swiftϓϩάϥϛϯάษڧձ 2016/5/19 36
  37. SE-0031: inoutଐੑͷҐஔͷมߋ inoutଐੑͷҐஔ͕:ͷޙͰɺҾ਺ͷܕͷલʹҠಈ͠·ͨ͠ɻ //for swift2.2 func foo(inout x: Int) {

    } //for swift3.0 func foo(x: inout Int) { } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 37
  38. SE-0043: caseจʹ͓͚Δෳ਺ύλʔϯΛಉ࣌ ʹຬͨ͢ม਺Λఆٛ enum MyEnum { case Case1(Int,Float) case Case2(Float,Int)

    } switch value { case let .Case1(x, 2), let .Case2(2, x): print(x) case .Case1, .Case2: break } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 38
  39. SE-0046: ؔ਺ݺͼग़͠ͷ͍͞ୈҰҾ਺ͷϥϕϧ Λඞਢʹ͢Δ func foo(x: Int, y: Int) Swiftϓϩάϥϛϯάษڧձ 2016/5/19

    39
  40. SE-0025: ΞΫηε੍ݶͷείʔϓ ͍··Ͱprivate͕ϑΝΠϧ୯ҐͷΞΫηε੍ݶͩͬͨͷΛείʔϓ୯Ґʹมߋ͠· ͢ʂ ΞΫηε੍ݶͷम০ࢠ͸ҎԼͷ̐ͭʹͳΓ·͢ • public: ݱࡏͷϞδϡʔϧͷ֎Ͱ΋ݟ͑Δम০ࢠ • internal:

    ݱࡏͷϞδϡʔϧͷதͰݟ͑Δम০ࢠ • fileprivate: ݱࡏͷϑΝΠϧ಺Ͱݟ͑Δम০ࢠ • private: ݱࡏͷείʔϓ಺ͷΈʹݟ͑Δम০ࢠ private͕ϑΝΠϧ୯ҐͰ͸ͳ͘είʔϓ୯ҐʹͳΔʂ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 40
  41. ίʔυྫ class A { private var counter = 0 //

    internalͷύϒϦοΫAPI func incrementCount() { ++counter } // ͜ͷείʔϓ͔Β֎͔Βݟ͑ͳ͍API private func advanceCount(dx: Int) { counter += dx } // incrementTwice() is not visible here } extension A { // counterϓϩύςΟ͸͔͜͜Β͸ݟ͑ͳ͍ɻ // advanceCount() ϝιου΋͔͜͜Β͸ݟ͑ͳ͍ // extension಺Ͱଞ͔Β͸ݟ͑ͳ͍ϝιουΛ࣮૷͢Δͷ͸༗ӹͳ৔߹͕͋Δɻ // incrementTwice()ϝιου͸͜ͷextensionΑΓ֎Ͱ͸ίʔυิ׬͕͞Εͳ͍ private func incrementTwice() { incrementCount() incrementCount() } } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 41
  42. SE-0054: ImplicitlyUnwrappedOptionalܕ Λ΍ΊΔ • ImplicitlyUnwrappedOptionalܕΛܕͱͯ͠ѻ͏ͷΛ΍Ίͯଐ ੑʹมߋ͠·͢ • !͸ͦͷ··࢖͑Δ Swiftϓϩάϥϛϯάษڧձ 2016/5/19

    42
  43. Objective-Cͱͷؔ܎Λ ݟ௚͢ 4બϐοΫΞοϓ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 43

  44. SE-0033: Objective-Cͷఆ਺ΛSwiftͷܕͱ͠ ͯΠϯϙʔτ Objective-Cͷఆ਺ΛSwiftͷenum΍structʹม׵͢ΔΑ Objective-CʹtypedefͱҰॹʹ৽͍͠ଐੑΛ૊Έ߹Θͤͯఆٛ ͢Δ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 44

  45. ྫ͑͹HealthKit identifiers͸Objecitve-CͰ ͸͜Μͳײ͡ʹఆٛͯ͠ typedef NSString * HKQuantityTypeIdentifier __attribute__((swift_wrapper(enum)); HK_EXTERN HKQuantityTypeIdentifier

    const HKQuantityTypeIdentifierBodyMassIndex; HK_EXTERN HKQuantityTypeIdentifier const HKQuantityTypeIdentifierBodyFatPercentage; HK_EXTERN HKQuantityTypeIdentifier const HKQuantityTypeIdentifierHeight; HK_EXTERN HKQuantityTypeIdentifier const HKQuantityTypeIdentifierBodyMass; HK_EXTERN HKQuantityTypeIdentifier const HKQuantityTypeIdentifierLeanBodyMass; Swiftϓϩάϥϛϯάษڧձ 2016/5/19 45
  46. Swiftଆ͸͜Μͳײ͡ʹenumͰม׵͞ΕΔ enum HKQuantityTypeIdentifier : String { case BodyMassIndex case BodyFatPercentage

    case Height case BodyMass case LeanBodyMass } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 46
  47. NSError͸͜Μͳײ͡ʹObjective-Cʹఆٛ͞Ε ͍ͯΔͱ͖ typedef NSString * NSErrorDomain __attribute__((swift_wrapper(struct))); FOUNDATION_EXPORT NSErrorDomain const

    NSCocoaErrorDomain; FOUNDATION_EXPORT NSErrorDomain const NSPOSIXErrorDomain; FOUNDATION_EXPORT NSErrorDomain const NSOSStatusErrorDomain; FOUNDATION_EXPORT NSErrorDomain const NSMachErrorDomain; Swiftϓϩάϥϛϯάษڧձ 2016/5/19 47
  48. Swiftଆ͸͜Μͳײ͡ʹstructʹม׵͞ΕΔ struct NSErrorDomain : RawRepresentable { typealias RawValue = String

    init(rawValue: RawValue) var rawValue: RawValue { get } static var Cocoa: NSErrorDomain { get } static var POSIX: NSErrorDomain { get } static var OSStatus: NSErrorDomain { get } static var Mach: NSErrorDomain { get } } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 48
  49. SE-0064: Objective-Cͷήολʔηολʔϓϩ ύςΟΛηϨΫλʔͰࢀর͢Δ #selectorͰObjective-Cͷgetterɺsetter͕ࢀরͰ͖ΔΑ͏ʹ͢Δ class Person: NSObject { dynamic var

    firstName: String dynamic let lastName: String dynamic var fullName: String { return "\(firstName) \(lastName)" } init(firstName: String, lastName: String) { self.firstName = firstName self.lastName = lastName } } let firstNameGetter = #selector(getter: Person.firstName) let firstNameSetter = #selector(setter: Person.firstName) Swiftϓϩάϥϛϯάษڧձ 2016/5/19 49
  50. SE-0069: ϛϡʔλϏϦςΟͱFoundationͷ஋ ܕ Objective-CͷFoundationͷͰΫϥεͰఆٛ͞Ε͍ͯͨ΋ͷΛSwiftͰ஋ܕʹఆٛ͢Δ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 50

  51. SE-0070: Make Optional Requirements Objective-C-only • Objevictive-Cͷϓϩτίϧ͸࣮૷ͯ͠΋͠ͳͯ͘΋Α͍ optionalम০ࢠ͕͚ͭΒΕΔɻ • Ͱ΋Swiftͷϓϩτίϧʹoptional͸͚ͭͨ͘ͳ͍ɻ

    • ͳͷͰɺOptionalम০ࢠΛObjective-CͷΈʹݶఆ͠·͢ɻ • optionalम০ࢠͷલʹ͸ඞͣ@objcम০ࢠΛ͚ͭΔΑ͏ʹ͠· ͢ɻ Swiftϓϩάϥϛϯάษڧձ 2016/5/19 51
  52. ྫ @objc protocol NSTableViewDelegate { @objc optional func tableView(_: NSTableView,

    viewFor: NSTableColumn, row: Int) -> NSView? // correct optional func tableView(_: NSTableView, heightOfRow: Int) -> CGFloat // error: 'optional' requirements are an Objective-C compatibility feature; add '@objc' } Swiftϓϩάϥϛϯάษڧձ 2016/5/19 52