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
380
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.8k
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
目標と時間軸 〜ベイビーステップでケイパビリティを高めよう〜
kakehashi
PRO
8
970
AWS Well-Architected Frameworkで学ぶAmazon ECSのセキュリティ対策
umekou
2
150
OPENLOGI Company Profile
hr01
0
60k
Ruby on Railsで持続可能な開発を行うために取り組んでいること
am1157154
3
160
クラウド食堂とは?
hiyanger
0
130
AIエージェント入門
minorun365
PRO
33
19k
Amazon Aurora のバージョンアップ手法について
smt7174
2
180
Platform Engineeringで クラウドの「楽しくない」を解消しよう
jacopen
4
190
What's new in Go 1.24?
ciarana
1
120
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
3
540
株式会社Awarefy(アウェアファイ)会社説明資料 / Awarefy-Company-Deck
awarefy
3
12k
1行のコードから社会課題の解決へ: EMの探究、事業・技術・組織を紡ぐ実践知 / EM Conf 2025
9ma3r
12
4.7k
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
461
33k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
115
51k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
How GitHub (no longer) Works
holman
314
140k
Typedesign – Prime Four
hannesfritz
41
2.5k
Site-Speed That Sticks
csswizardry
4
410
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Code Reviewing Like a Champion
maltzj
521
39k
Become a Pro
speakerdeck
PRO
26
5.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
21
2.5k
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