Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
roppongiswift6.pdf
Search
tanako
December 21, 2018
Technology
1
390
roppongiswift6.pdf
「ROPPONGI.swift 第6回 望年会」での発表資料です。
tanako
December 21, 2018
Tweet
Share
More Decks by tanako
See All by tanako
タイミーiOSアプリへの Swift Concurrency 導入までの軌跡
_tanako
4
1.9k
SwiftPM Integration into Xcode
_tanako
0
140
iOSエンジニアの為のgrpc-swift入門
_tanako
6
4.7k
grpc-swiftの紹介
_tanako
0
1.7k
How to write basic unittests
_tanako
0
190
Other Decks in Technology
See All in Technology
CodeRabbitと過ごした1ヶ月 ─ AIコードレビュー導入で実感したチーム開発の進化
mitohato14
1
230
Notion x ポストモーテムで広げる組織の学び / Notion x Postmortem
isaoshimizu
1
150
【Oracle Cloud ウェビナー】ご希望のクラウドでOracle Databaseを実行〜マルチクラウド・ソリューション徹底解説〜
oracle4engineer
PRO
1
140
地味にいろいろあった! 2025春のAmazon Bedrockアップデートおさらい
minorun365
PRO
2
550
genspark_presentation.pdf
haruki_uiru
0
150
Simplify! 10 ways to reduce complexity in software development
ufried
1
190
AIでめっちゃ便利になったけど、結局みんなで学ぶよねっていう話
kakehashi
PRO
1
520
SREからゼロイチプロダクト開発へ ー越境する打席の立ち方と期待への応え方ー / Product Engineering Night #8
itkq
2
1.1k
AWSの新機能検証をやる時こそ、Amazon Qでプロンプトエンジニアリングを駆使しよう
duelist2020jp
1
330
AI-in-the-Enterprise|OpenAIが公開した「AI導入7つの教訓」——ChatGPTで変わる企業の未来とは?
customercloud
PRO
0
110
勝手に!深堀り!Cloud Run worker pools / Deep dive Cloud Run worker pools
iselegant
4
620
Twelve-Factor-Appから学ぶECS設計プラクティス/ECS practice for Twelve-Factor-App
ozawa
3
160
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
Designing for humans not robots
tammielis
253
25k
The Cost Of JavaScript in 2023
addyosmani
49
7.8k
Optimising Largest Contentful Paint
csswizardry
37
3.2k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.4k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
GraphQLの誤解/rethinking-graphql
sonatard
71
10k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Transcript
Swift5ͷ৽ػೳʢൈਮʣ ROPPONGI.swift ୈ6ճ ձ Koichi Tanaka @tikidunpon 2018/12/21
Koichi Tanaka Origami inc. I love Swift/Go
ே׆ͬͯ·͢ʢஶऀͰͳ͍Ͱ͢ɻʣ
Agenda • ABI҆ఆԽͷঢ়گ • ֤Proposalͷઆ໌ʢશ෦ແཧͳͷͰൈਮʣ
ABI҆ఆԽͷঢ়گ
None
ABI҆ఆԽͷঢ়گ • https://swift.org/abi-stability Ͱ֬ೝͰ͖Δ • υΩϡϝϯτ࡞Λͯ͠΄΅͍ྃͯ͠ΔΑ͏ʹݟ͑Δ
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
ABI҆ఆԽͰΞϓϦαΠζݮΔ͔ʁ
֤Proposalͷઆ໌ʢൈਮʣ
SE-0192 Handling Future Enum Cases
কདྷՃ͞ΕΔέʔεͷϋϯυϦϯά • frozenʢ˞1ʣͱnon-frozenʢ˞2ʣͳEnumΛ۠ผ͢Δ • ϢʔβʔఆٛͷSwiftͷEnumfrozenʹϚʔΫ͞ΕΔ • ࠓճͷมߋͰCݴޠAppleͷඪ४ϥΠϒϥϦʹ͚ͩӨڹ • @unknownଐੑͷՃ ※1
frozenίʔυ͕ॻ͔Εͨ࣌Ͱcase͕Ճ͞Εͳ͍ ※2 non-frozenίʔυ͕ॻ͔Εͨ࣌Ͱcase͕Ճ͞ΕΔ͔
ԾʹiOSʹ͜Μͳenum͕͋Δͱ͖ʹ enum State { case foo case bar case baz
}
έʔεΛཏ͢ΔͳΒ͜͏ॻ͚·ͨ͠ func handle(state: State) { switch state { case .foo:
print("do foo stuff") case .bar: print("do bar stuff") case .baz: print("do baz stuff") } }
͔͠͠iOSͷόʔδϣϯΞοϓͰenumʹέʔε͕Ճ͞Ε.. enum State { case foo case bar case baz
case foobar //Ճ }
ະఆٛͷέʔε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 } }
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") } }
SE-0200 Enhancing String Literals Delimiters to Support Raw Text
RawςΩετΛαϙʔτ͢ΔσϦϛλͷՃ • ͍··Ͱ\ΛΤεέʔϓ͢Δ࣌ʹ\\ͱॻ͔ͳ͍ͱ͍͚ͳ͍ • #͕σϦϛλͱͯ͠Ճ͞Εͨ • ੜσʔλΛίϐϖՄೳͱͳΓՄൖੑ͕ߴ·Δ
//͍··Ͱ let regex1 = "\\\\[A-Z]+[A-Za-z]+\\.[a-z]+" //Swift5 let regex2 = #"\\[A-Z]+[A-Za-z]+\.[a-z]+"#
SE-0211 Add Unicode Properties to Unicode.Scalar
Unicode.ScalarPropertiesͷՃ • Scalar͕Uppercase͔ఆ͢Δํ๏͕ͳ͔ͬͨ • ࡉ͔͍UnicodeपΓͷॲཧΛ͢Δʹݱঢ়ICUʢ˞1ʣʹґଘ • ͕ͩICUΛ੩తʹϦϯΫ͠ͳ͍ͱϦδΣΫτ͞ΕΔʢ˞2ʣ ※1 ICU =
International Components for Unicode ※2 Issues Linking with ICU
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
SE-0213 Literal initialization via coercion
ڧ੍తͳϦςϥϧॳظԽ • Swift4.2ͰA(B)ͱA.init(B)͕ඞͣ͠ಉ݁͡ՌͱͳΒͳ͍ • σϑΥϧτͷܕͰਪ͞Εͯ͠·͏ • ظ͠ͳ͍݁ՌΦʔόʔϑϩʔ͕ى͖ͨΓͨ͠
Swift4.2 // ݁Ռ͕ҟͳΔʂ let c = 3.14159265358979323846 as Float80 //
3.14159265358979323851 let d = Float80(3.14159265358979323846) // 3.141592653589793116
Swift5 // ݁Ռ͕ಉ͡ʂ let c = 3.14159265358979323846 as Float80 //
3.1415926535897932385 let d = Float80(3.14159265358979323846) // 3.1415926535897932385
Swift5ͰA(B)ͷؔݺͼग़͠ͰB͕Ϧςϥϧࣜͷ࣌ɺ͠A͕ T.TypeΛ͍͔࣋ͬͯͯͭT͕Bʹରͯ͠దͳϦςϥϧϓϩτίϧ ʢExpressibleByStringLiteralͱ͔ʣʹ४ڌ͍ͯ͠Δ࣌AinitΛ ͬͯߏங͞ΕΔɻʢB as Aͱॻ͔Ε͍ͯΔ͔ͷΑ͏ʹʣ SE-0213 Detailed design͔ΒҾ༻༁
SE-0218 Introduce compactMapValues to Dictionary by @d_date
compactMapValuesΛDictionaryՃ
compactMapValuesΛDictionaryՃ • mapValueͰdictionaryͷ͚ͩΛऔΓग़͢͜ͱग़དྷͨ
compactMapValuesΛDictionaryՃ • mapValueͰdictionaryͷ͚ͩΛऔΓग़͢͜ͱग़དྷͨ • ʹnilΛؚΉdictinaryͷ߹ਏ͔ͬͨ
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"]
Swift5 // optionalΛʹͭdictionary let d: [String: String?] = ["a": "1",
"b": nil, "c": "3"] let r3 = d.compactMapValues{ $0 } // r3 = ["c": "3", "a": "1"] ॱংෆఆ
SE-0235 Add Result to the Standard Library
ඪ४ϥΠϒϥϦʹResultܕ͕Ճ͞Εͨ • ޭ͔ࣦഊΛදݱ͢Δܕ • ಛʹඇಉظॲཧͷΤϥʔΛѻ͍ͮΒ͔ͬͨ • ͜Ε·Ͱantitypical/Result͕ྑ͘ΘΕ͍ͯͨ
͍··Ͱʢ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) }
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) } }
ݱ࣌ͰҎԼͷΑ͏ʹॻ͚Δ 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ͱ͔ੜ͑ͯΔʣ
SE-0215 Conform Never to Equatable and Hashable
Never͕EquatableͱHashableʹ४ڌ • Never݅ͳ͠ʹΤϥʔtrapͤ͞Δɺຢऴྃ͠ͳ͍ؔͷ Γʹར༻Մೳ • ྫ͑faitalErrorؔͷΓNever • ࣦഊ͠ͳ͍ॲཧʹResult<T, Never>Λ͍͍ͨ •
Swift4.2ͰResult<T, Never>ൺֱग़དྷͳ͍
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") }
·ͱΊʢײʣ • Ұ൪ABI҆ఆԽ • จࣈपΓڧԽ͞Εͨʢকདྷͷਖ਼نදݱαϙʔτʹ͍ۙͮͨʁʣ • ProposalಡΉͷָ͍͚͠Ͳແݶʹ༹͕͚࣌ؒΔ • iOS12 Programmingຊ͕ࣄલֶशʹྑ͔ͬͨ
એʢஶऀͰͳ͍Ͱ͢ɻʣ
ࢀߟࢿྉ • 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
Thanks!! Koichi Tanaka @tikidunpon