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
What’s new in Swift? (from WWDC 2020)
Search
Kazutaka Homma
July 21, 2020
Programming
1
4.3k
What’s new in Swift? (from WWDC 2020)
This is the slides I used in Reacap of WWDC20 by Mercari
https://mercari.connpass.com/event/180254/
Kazutaka Homma
July 21, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
7
1.4k
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
1.8k
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
250
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
370
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
3
190
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
2
2.6k
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
0
110
2025.01.17_Sansan × DMM.swift
riofujimon
2
530
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
440
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
1.1k
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
230
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
170
14k
Designing for humans not robots
tammielis
250
25k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Into the Great Unknown - MozCon
thekraken
34
1.6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Power of CSS Pseudo Elements
geoffreycrofte
74
5.4k
RailsConf 2023
tenderlove
29
970
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.5k
Writing Fast Ruby
sferik
628
61k
BBQ
matthewcrist
85
9.4k
Transcript
What’s new in Swift? @Kaz_Homma (Kazutaka Homma)
@Kaz_Homma (本間 和尊) iOS Engineer at Mercari JP Joined on
July, 2019 Github: @Kazutaka333 Twitter: @Kaz_Homma 2
1. Multiple trailing closures 複数クロージャーでもカッコを省略して引数に書ける! 2. Increased availability of implicit
self in closures selfを書く回数が減る! 3. Synthesized Comparable conformance for enum types enumにComparableプロトコルが使いやすくなった! 4. Enum cases as protocol witnesses Enum caseでstatic var・static funcを満たすことができる! 5. KeyPath expressions as function keyPathをクロージャーの代わりに渡せる! Agenda 3
Multiple trailing closures SE-0279 // Trailing Closure なし UIView.animate(withDuration: 0.1,
animations: { self.view.backgroundColor = .red }) // Trailing Closure あり // 引数の省略かつ、ネストを減らしたシンプルな見た目 UIView.animate(withDuration: 0.1) { self.view.backgroundColor = .red } 1/4 4
// Swift5.2 // Trailing Closureなし UIView.animate(withDuration: 0.3, animations: { self.view.alpha
= 0 }, completion: { _ in self.view.removeFromSuperview() }) Multiple trailing closures SE-0279 2/4 // Trailing Closureあり // 引数名が省略されていて2つ目のclosureが // わかりにくい UIView.animate(withDuration: 0.3, animations: { self.view.alpha = 0 }) { _ in self.view.removeFromSuperview() } 5
// Swift5.2 // Multiple Trailing Closureなし // 引数名が省略されいて 2つ目のclosureがわかりにくい UIView.animate(withDuration:
0.3, animations: { view.alpha = 0 }) { _ in view.removeFromSuperview() } Multiple trailing closures SE-0279 3/4 // Swift5.3 // Multiple trailing closureをつかうと… // 少ないネストかつ、2つ目のclosureの引数もあるので // わかりやすい UIView.animate(withDuration: 0.3) { view.alpha = 0 } completion: { _ in view.removeFromSuperview() } 6
// もっとmultiple trailing closures... func animate(animation: (() -> Void), preparation:
(() -> Void), completion: ((Bool) -> Void)) { // hoge hoge... } animate { // animating... } preparation: { // preparing... } completion: { result in // completing task... } Multiple trailing closures SE-0279 4/4 7
// たくさんのself... UIView.animate(withDuration: 0.3) { self.recordingView?.alpha = 0.0 self.textView.alpha =
1.0 } completion: { _ in self.activeTransitionCount -= 1 if !self.isRecording && self.activeTransitionCount == 0 { self.recordingView?.removeFromSuperview() self.recordingView = nil } } Increased availability of implicit self in closures SE-0269 1/4 8
Increased availability of implicit self in closures SE-0269 // Swift5.3ではselfをキャプチャすればclosure内で
// 省略できる UIView.animate(withDuration: 0.3) { [self] in recordingView?.alpha = 0.0 textView.alpha = 1.0 } completion: { [self] _ in activeTransitionCount -= 1 if !isRecording && activeTransitionCount == 0 { recordingView?.removeFromSuperview() recordingView = nil } } // たくさんのself… UIView.animate(withDuration: 0.3) { self.recordingView?.alpha = 0.0 self.textView.alpha = 1.0 } completion: { _ in self.activeTransitionCount -= 1 if !self.isRecording && self.activeTransitionCount == 0 { self.recordingView?.removeFromSuperview() self.recordingView = nil } } 2/4 9
Increased availability of implicit self in closures SE-0269 // weak
selfは今まで通りです UIView.animate(withDuration: 0.3) { [weak self] in guard let self = self else { return } self.recordingView?.alpha = 0.0 self.textView.alpha = 1.0 } UIView.animate(withDuration: 0.3) { [weak self] in self?.recordingView?.alpha = 0.0 self?.textView.alpha = 1.0 } 3/4 10
Increased availability of implicit self in closures SE-0269 4/4 11
Synthesized Comparable conformance for enum types SE-0266 12 1/3 //
まずComparableとは? struct Date { let year: Int let month: Int let day: Int } extension Date: Comparable { static func < (lhs: Date, rhs: Date) -> Bool { if lhs.year != rhs.year { return lhs.year < rhs.year } else if lhs.month != rhs.month { return lhs.month < rhs.month } else { return lhs.day < rhs.day } } } print(Date(year: 10, month: 10, day: 10) > Date(year: 10, month: 10, day: 9)) // true
Synthesized comparable conformance for enum types SE-0266 // Swift 5.3未満
enum Membership: Int, Comparable { case basic case silver case gold static func < (lhs: Self, rhs: Self) -> Bool { return lhs.rawValue < rhs.rawValue } } print(Membership.basic < Membership.silver) // true print(Membership.silver < Membership.gold) // true print(Membership.basic > Membership.gold) // false 13 2/3
Synthesized comparable conformance for enum types SE-0266 // Swift 5.3以前
enum Membership: Int, Comparable { case basic case silver case gold static func < (lhs: Self, rhs: Self) -> Bool { return lhs.rawValue < rhs.rawValue } } print(Membership.basic < Membership.silver) // true print(Membership.silver < Membership.gold) // true print(Membership.basic > Membership.gold) // false 14 3/3 // Swift 5.3では簡略化できる enum Membership: Comparable { case basic case silver case gold } print(Membership.basic < Membership.silver) // true print(Membership.silver < Membership.gold) // true print(Membership.basic > Membership.gold) // false
Enum cases as protocol witnesses SE-0280 15 1/5
Enum cases as protocol witnesses SE-0280 16 2/2
KeyPath expressions as function SE-0249 17 1/4
KeyPath expressions as function SE-0249 18 2/4
KeyPath expressions as function SE-0249 19 3/4
KeyPath expressions as function SE-0249 20 4/4 Swift 5.2からは必要ない
1. Multiple trailing closures 複数クロージャーでもカッコを省略して引数に書ける! 2. Increased availability of implicit
self in closures selfを書く回数が減る! 3. Synthesized Comparable conformance for enum types enumにComparableプロトコルが使いやすくなった! 4. Enum cases as protocol witnesses Enum caseでstatic var・static funcを満たすことができる! 5. KeyPath expressions as function keyPathをクロージャーの代わりに渡せる! おさらい 21
Thank you 22