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
350
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.6k
SwiftPM Integration into Xcode
_tanako
0
140
iOSエンジニアの為のgrpc-swift入門
_tanako
6
4.6k
grpc-swiftの紹介
_tanako
0
1.7k
How to write basic unittests
_tanako
0
180
Other Decks in Technology
See All in Technology
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
750
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
Terraform Stacks入門 #HashiTalks
msato
0
350
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.2k
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
520
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Teambox: Starting and Learning
jrom
133
8.8k
Making Projects Easy
brettharned
115
5.9k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Fireside Chat
paigeccino
34
3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
BBQ
matthewcrist
85
9.3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
How to Ace a Technical Interview
jacobian
276
23k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
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