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
バックポートして学ぶ新APIの仕組み
Search
Yutaro Muta
September 11, 2022
Programming
0
2.7k
バックポートして学ぶ新APIの仕組み
iOSDC Japan 2022
https://fortee.jp/iosdc-japan-2022/proposal/ae6ff1d3-0777-4804-9407-5a081fba313d
Yutaro Muta
September 11, 2022
Tweet
Share
More Decks by Yutaro Muta
See All by Yutaro Muta
Swiftの “private” を テストする / Testing Swift "private"
yutailang0119
0
170
Apple Vision Pro購入RTA 1泊3日弾丸ハワイツアー / RTA: Purchase Apple Vision Pro in Hawaii
yutailang0119
0
1.4k
個人開発のたのしみ / Enjoying personal development
yutailang0119
0
950
Backport AsyncImage
yutailang0119
0
690
xcrun Essentials
yutailang0119
6
1.2k
Let's Coding SwiftUI on iPad!
yutailang0119
1
500
Property Wrapperで遊ぼう / Play with Property Wrapper
yutailang0119
2
300
Back of First Screen AB test of Hatena Bookmark iOS app with Firebase AB Testing
yutailang0119
0
300
Lab of WWDC19
yutailang0119
1
510
Other Decks in Programming
See All in Programming
AIコーディングワークフローの試行 〜AIエージェント×ワークフローでの自動化を目指して〜
rkaga
3
3.7k
RuboCop: Modularity and AST Insights
koic
2
790
AIコードエディタの基盤となるLLMのFlutter性能評価
alquist4121
0
210
地域ITコミュニティの活性化とAWSに移行してみた話
yuukis
0
240
Vibe Codingをせずに Clineを使っている
watany
17
6.3k
Dissecting and Reconstructing Ruby Syntactic Structures
ydah
0
700
State of Namespace
tagomoris
4
1.6k
プロダクト横断分析に役立つ、事前集計しないサマリーテーブル設計
hanon52_
2
440
Ruby's Line Breaks
yui_knk
2
1k
状態と共に暮らす:ステートフルへの挑戦
ypresto
1
540
AI時代の開発者評価について
ayumuu
0
150
サービスレベルを管理してアジャイルを加速しよう!! / slm-accelerate-agility
tomoyakitaura
1
180
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
245
12k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
KATA
mclloyd
29
14k
StorybookのUI Testing Handbookを読んだ
zakiyama
29
5.6k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
9
750
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
13
670
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.2k
4 Signs Your Business is Dying
shpigford
183
22k
[RailsConf 2023] Rails as a piece of cake
palkan
54
5.4k
Thoughts on Productivity
jonyablonski
69
4.6k
Transcript
バックポートして学ぶ 新APIの仕組み Yutaro Muta / @yutailang0119 2022/09/11 iOSDC JAPAN 2022
Who am I!? • Yutaro Muta ◦ @yutailang0119 • Hatena
Co., Ltd. ◦ @Kyoto
前置き SBPAsyncImageの紹介
yutailang0119/SBPAsyncImage • Backport of SwiftUI.AsyncImage to iOS 14, macOS 11,
tvOS 14 and watchOS 7 and earlier. • SwiftUI.AsyncImageは2021年OSから ◦ iOS 15.0+ iPadOS 15.0+ macOS 12.0+ Mac Catalyst 15.0+ tvOS 15.0+ watchOS 8.0+
SwiftUI.AsyncImage struct AsyncImage<Content> where Content : View AsyncImage(url: URL(string: “https://example.com/icon.png"))
.frame(width: 200, height: 200) BackportAsyncImage struct BackportAsyncImage<Content> where Content : View BackportAsyncImage(url: URL(string: “https://example.com/icon.png")) .frame(width: 200, height: 200)
Goal • バックポートにおける戦略の共有 ◦ SBPAsyncImageの例 • バックポートのおもしろさを発見
Agenda • なぜバックポートするのか • 新APIの調べ方 • バックポート実装のTips • メンテナンス上の難点 •
まとめ
Agenda • なぜバックポートするのか • 新APIの調べ方 • バックポート実装のTips • メンテナンス上の難点 •
まとめ
なぜバックポートするのか
なぜバックポートするのか • WWDCのアップデートは一部を除き、最新 OSにのみ提供される • アプリによっては、使えるのは数年後
なぜバックポートするのか • 例外もある • Swift Concurrency関連のAPIの一部は、 公式でバックポートされている ▪ Xcode 14.0で、URLSessionのバックポートが増えた
iOS 13.0+ iPadOS 13.0+ macOS 10.15+ Mac Catalyst 16.0+ Beta tvOS 13.0+ watchOS 6.0+ func data(from url: URL) async throws -> (Data, URLResponse)
Agenda • なぜバックポートするのか • 新APIの調べ方 • バックポート実装のTips • メンテナンス上の難点 •
まとめ
新APIの調べ方
新APIの調べ方 • Apple Developer Document ◦ API diff ◦ Technologies
• Videos • Xcode ◦ Jump to Definition ⌃⌘
Apple Developer Document
• ?changes=latest_beta • ?changes=latest_minor • ?changes=latest_major API diff
https://developer.apple.com/documentation/technologies?changes=latest_minor
新APIの調べ方 • Apple Developer Document ◦ API diff ◦ Technologies
• Videos • Xcode ◦ Jump to Definition ⌃⌘
新APIの調べ方 • Apple Developer Document ◦ API diff ◦ Technologies
• Videos • Xcode ◦ Jump to Definition ⌃⌘ 根気強く見ていく
https://yutailang0119.hatenablog.com/entry/2022/02/24/163000 宣伝 【2022年】Xcode/Apple Platform/Swiftアップデートの歩き方
Agenda • なぜバックポートするのか • 新APIの調べ方 • バックポート実装のTips • メンテナンス上の難点 •
まとめ
バックポート実装のTips
バックポート実装のTips • サポートOSの範囲 • ライブラリ、モジュールの名付け • Beta期間の取り扱い
サポートOSの範囲
サポートOSの範囲 • 2022年における基本はiOS 13+ ◦ Module Stabilityが達成されたSwift 5.1が同梱され たのがiOS 13
▪ Swift ConcurrencyのバックポートもiOS 13+ ◦ SwiftUIのAvailabilityがiOS 13+ • サポート範囲、動作の割り切りも必要 ◦ Appleも苦戦する領域
ライブラリ、 モジュールの名付け
ライブラリ、モジュールの名付け • 名前衝突を避ける工夫 • SE-0339 ◦ Module Aliasing For Disambiguation
名前衝突を避ける工夫
名前衝突を避ける工夫 • 伝統的なPrefix回避 ◦ e.g. ▪ IBP = iOS Backport
▪ SBP = Swift Backport • 冗長にバックポートとわかる名前を付ける ◦ e.g. BackportAsyncImage
SE-0339 Module Aliasing For Disambiguation
SE-0339 Module Aliasing For Disambiguation • SwiftPM 5.7+ ◦ Xcode
14.0+ • moduleAliasesキーワードで、パッケージの 外からモジュール名を変更可能 • 利用側で指定が必要
SE-0339 Module Aliasing For Disambiguation // swift-tools-version: 5.7 targets: [
.executableTarget( name: "App", dependencies: [ .product(name: "Game", package: "swift-game", moduleAliases: ["Utils": "GameUtils"]), .product(name: "Utils", package: "swift-draw"), ]) ]
Beta期間の取り扱い
Beta期間の取り扱い • Beta期間はインターフェース、挙動ともに破 壊的変更が何度も起こるものとして注視 ◦ API diff ?changes=latest_beta • 現行Stable、過去のXcodeサポートの有無
Agenda • なぜバックポートするのか • 新APIの調べ方 • バックポート実装のTips • メンテナンス上の難点 •
まとめ
メンテナンス上の難点
メンテナンス上の難点 • 小さい機能を支える広い領域 • OS毎の挙動差 • Originとの優先度
小さい機能を 支える広い領域
小さい機能を支える広い領域 • e.g. AsyncImage ◦ SwiftUI ▪ @StateObject, @ObservedObject, @Published,
ViewBuilder ◦ UIKit ▪ UIImage ◦ AppKit ▪ NSImage ◦ Foundation ▪ URLSession
OS毎の挙動差
OS毎の挙動差 • OSバージョン毎に利用できる手段の差異 ◦ iOS 14+ @StateObject ◦ iOS 13+
@ObservedObject • プラットフォーム毎にフレームワークの差異 ◦ UIKit vs AppKit ▪ e.g. UIImage vs NSImage
Originとの優先度
• 利用側にOriginとバックポート実装のどちら を優先させるか、考える必要あり Originとの優先度 Beta期間 Stable~その後 Origin @available調整 Backport 現行Xcodeのサポート
SBPAsyncImageの戦略
• AsyncImageの利用可能なOSが浸透すれば、 バックポートは役目を終えていく ◦ iOS 15+の世界 ◦ 段階的に移行させたい • Beta期間からAsyncImageを感じたい
SBPAsyncImageの戦略
• Originを優先し、移行を促す戦略 ◦ @availableを駆使 ▪ deprecated, obsoleted, unavailable • バックポート実装は独立させる戦略
◦ 利用側は別物として扱う SBPAsyncImageの戦略
• typealiasでOriginに合わせ、意識せずに利用 させる ▪ ▪ ▪ @available ▪ モジュールを指名することで、使い分け可能 @available(iOS,
deprecated: 15.0, renamed: "SwiftUI.AsyncImage") public typealias AsyncImage = BackportAsyncImage SBPAsyncImageの戦略
Agenda • なぜバックポートするのか • 新APIの調べ方 • バックポート実装のTips • メンテナンス上の難点 •
まとめ
まとめ
まとめ • バックポートには、機能開発と違う難易度、 視点、マインドがある • 2022年におけるサポートOSは最低iOS 13+ • バックポートはOriginの実装、挙動を熟知で きるのでおすすめ
References • https://github.com/yutailang0119/SBPAsyncImage • https://developer.apple.com/documentation/swiftui/asyncimage • https://developer.apple.com/documentation/foundation/urlsession/3919873-data • https://developer.apple.com/documentation •
https://developer.apple.com/documentation/technologies?changes=latest_minor • https://yutailang0119.hatenablog.com/entry/2022/02/24/163000 • https://github.com/apple/swift-evolution/blob/main/proposals/0339-module-aliasing-f or-disambiguation.md • https://developer.apple.com/documentation/packagedescription/target/dependency/pr oduct(name:package:modulealiases:) • https://docs.swift.org/swift-book/ReferenceManual/Attributes.html
Enjoy iOSDC, Thanks!!! • @yutailang0119 • yutailang0119
hatena.co.jp/recruit