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
360
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.7k
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
180
Other Decks in Technology
See All in Technology
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
Jetpack Composeで始めるServer Cache State
ogaclejapan
2
170
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
110
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
210
Wvlet: A New Flow-Style Query Language For Functional Data Modeling and Interactive Data Analysis - Trino Summit 2024
xerial
1
110
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
520
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
2
250
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
140
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
1
170
Postman と API セキュリティ / Postman and API Security
yokawasa
0
200
watsonx.ai Dojo #5 ファインチューニングとInstructLAB
oniak3ibm
PRO
0
160
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
4 Signs Your Business is Dying
shpigford
181
21k
Rails Girls Zürich Keynote
gr2m
94
13k
Music & Morning Musume
bryan
46
6.2k
Thoughts on Productivity
jonyablonski
67
4.4k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
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