roppongiswift6.pdf

E1cf27d9fa565b2867d171f21a39759c?s=47 tikidunpon
December 21, 2018

 roppongiswift6.pdf

「ROPPONGI.swift 第6回 望年会」での発表資料です。

E1cf27d9fa565b2867d171f21a39759c?s=128

tikidunpon

December 21, 2018
Tweet

Transcript

  1. 6.
  2. 8.

    Data Layout • SR-3730 Create technical specification of the layout

    algorithms Type Metadata • SR-3731 Technical specification for the fixed part of the metadata layout of all language constructs Mangling • Done Calling Convention • SR-4349 Document the function signature lowering scheme
  3. 14.

    έʔεΛ໢ཏ͢ΔͳΒ͜͏ॻ͚·ͨ͠ func handle(state: State) { switch state { case .foo:

    print("do foo stuff") case .bar: print("do bar stuff") case .baz: print("do baz stuff") } }
  4. 16.

    ະఆٛͷέʔεfoobar͕ϋϯυϧ͞ΕΔͱΫϥογϡ͠·͢ func handle(state: State) { switch state { case .foo:

    print("do foo stuff") case .bar: print("do bar stuff") case .baz: print("do baz stuff") // Fatal error: unexpected enum case } }
  5. 17.

    Swift5Ͱ@unknownଐੑ͕௥Ճ // কདྷ௥Ճ͞ΕΔະఆٛέʔε͸defaultΛ௨Δ // έʔεΛ໢ཏͯ͠ͳ͍ͱʮSwitch must be exhaustiveʯͷܯࠂ͕ग़Δҝɺ // ίϯύΠϧ࣌ʹcase͕૿͍͑ͯΔ͜ͱʹؾ͕͚ͭΔɻ

    // ͜ͷڍಈ͸ࣗ෼ͰNS_ENUMΛఆٛͯ͠importʢnon-frozenʣ͢Δͱ֬ೝͰ͖Δɻ func handle(state: State) { switch state { case .foo: print("do foo stuff") case .bar: print("do bar stuff") case .baz: print("do baz stuff") @unknown default: print("default") } }
  6. 23.

    Unicode.Scalar.PropertiesʹICUಉ༷ͷॲཧ͕ଟ͘௥Ճ let s: Unicode.Scalar = "9" print(s.properties.isASCIIHexDigit) //true let a:

    Unicode.Scalar = "a" print(a.properties.isLowercase) //true let emoji: Unicode.Scalar = " ! " print(emoji.properties.isEmoji) //true print(emoji.properties.isEmojiModifier) //false print(emoji.properties.isEmojiPresentation) //true let emojiModifier: Unicode.Scalar = "\u{1F3FB}" print(emojiModifier.properties.isEmojiModifier) //true
  7. 26.

    Swift4.2 // ݁Ռ͕ҟͳΔʂ let c = 3.14159265358979323846 as Float80 //

    3.14159265358979323851 let d = Float80(3.14159265358979323846) // 3.141592653589793116
  8. 27.

    Swift5 // ݁Ռ͕ಉ͡ʂ let c = 3.14159265358979323846 as Float80 //

    3.1415926535897932385 let d = Float80(3.14159265358979323846) // 3.1415926535897932385
  9. 33.

    Swift4.2 //mapValueͰdictionaryͷ஋͚ͩΛऔΓग़ͯ͠ૢ࡞͕Մೳ let a = ["John": 1, "Bob": 2, "Alice":

    3] let b = a.mapValues{ $0 * 2 } //b = ["Bob": 4, "Alice": 6, "John": 2] ॱং͸ෆఆ // optionalΛ஋ʹ΋ͭdictionary let d: [String: String?] = ["a": "1", "b": nil, "c": "3"] let r1 = d.filter { $0.value != nil }.mapValues { $0! } let r2 = d.reduce(into: [String: String]()) { (result, item) in result[item.key] = item.value } // r1 == r2 == ["a": "1", "c": "3"]
  10. 34.

    Swift5 // optionalΛ஋ʹ΋ͭdictionary let d: [String: String?] = ["a": "1",

    "b": nil, "c": "3"] let r3 = d.compactMapValues{ $0 } // r3 = ["c": "3", "a": "1"] ॱং͸ෆఆ
  11. 37.

    ͍··ͰʢProposal͔ΒҾ༻ʣ URLSession.shared.dataTask(with: url) { (data, response, error) in guard error

    != nil else { self.handleError(error!) } guard let data = data, let response = response else { return // Impossible? } handleResponse(response, data: data) }
  12. 38.

    Result͕ೖͬͨΒ͜ΜͳΠϝʔδʢProposal͔ΒҾ༻ʣ ※ ·ͩURLSessionʹ͜ͷ࣮૷͸ͳ͍ URLSession.shared.dataTask(with: url) { (result: Result<(URLResponse, Data), Error>)

    in switch result { case .value(let response): handleResponse(response.0, data: response.1) case .error(let error): handleError(error) } }
  13. 39.

    ݱ࣌఺ͰҎԼͷΑ͏ʹॻ͚Δ swift-5.0-DEVELOPMENT-SNAPSHOT-2018-12-20 enum Err: Error, Equatable { case err case

    derr } func notThrowing() throws -> String { return "string" } func throwing() throws -> String { throw Err.err } let result1 = Result { try throwing() } let result2 = Result { try notThrowing() } print(type(of: result1)) //Result<String, Error> print(type(of: result2)) //Result<String, Error> print(try result2.get()) //stringʢ੒ޭ஋ΛͱΔgetͱ͔ੜ͑ͯΔʣ
  14. 42.

    Swift5Ͱ͸NeverΛؚΉResult͕ൺֱͰ͖Δ let r1: Result<String, Never> let r2: Result<String, Never> r1

    = Result.success("success") r2 = Result.success("success") if r1 == r2 { print("r1 == r2") }
  15. 45.

    ࢀߟࢿྉ • What’s new in Swift 5 by @d_date •

    What’s new in Swift 5.0 by @twostraws • swift-evolution#version=5 • Swift ABI Dashboard