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
400
roppongiswift6.pdf
「ROPPONGI.swift 第6回 望年会」での発表資料です。
tanako
December 21, 2018
Tweet
Share
More Decks by tanako
See All by tanako
タイミーiOSアプリへの Swift Concurrency 導入までの軌跡
_tanako
4
2k
SwiftPM Integration into Xcode
_tanako
0
150
iOSエンジニアの為のgrpc-swift入門
_tanako
6
4.8k
grpc-swiftの紹介
_tanako
0
1.7k
How to write basic unittests
_tanako
0
200
Other Decks in Technology
See All in Technology
Long journey of Continuous Delivery at Mercari
hisaharu
1
220
AWS アーキテクチャ作図入門/aws-architecture-diagram-101
ma2shita
24
8.8k
マルチテナント+マルチプロダクト SaaS への AI Agent の組み込み方
kworkdev
PRO
2
370
自分を理解するAI時代の準備 〜マイプロフィールMCPの実装〜
edo_m18
0
110
New Cache Hierarchy for Container Images and OCI Artifacts in Kubernetes Clusters using Containerd / KubeCon + CloudNativeCon Japan
pfn
PRO
0
170
vLLM meetup Tokyo
jpishikawa
1
240
DroidKnights 2025 - Jetpack XR 살펴보기: XR 개발은 어떻게 이루어지는가?
heesung6701
1
130
Amazon Q Developer for GitHubとAmplify Hosting でサクッとデジタル名刺を作ってみた
kmiya84377
0
3.5k
Perk アプリの技術選定とリリースから1年弱経ってのふりかえり
stomk
0
110
Whats_new_in_Podman_and_CRI-O_2025-06
orimanabu
3
180
TerraformをSaaSで使うとAzureの運用がこんなに楽ちん!HCP Terraformって何?
mnakabayashi
0
180
Javalinの紹介
notoh
0
110
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
35
6.7k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Into the Great Unknown - MozCon
thekraken
39
1.8k
Gamification - CAS2011
davidbonilla
81
5.3k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Designing for humans not robots
tammielis
253
25k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
660
Code Reviewing Like a Champion
maltzj
524
40k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Scaling GitHub
holman
459
140k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
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