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.9k
バックポートして学ぶ新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
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
210
Swiftの “private” を テストする / Testing Swift "private"
yutailang0119
0
250
Apple Vision Pro購入RTA 1泊3日弾丸ハワイツアー / RTA: Purchase Apple Vision Pro in Hawaii
yutailang0119
0
1.4k
個人開発のたのしみ / Enjoying personal development
yutailang0119
0
1k
Backport AsyncImage
yutailang0119
0
740
xcrun Essentials
yutailang0119
6
1.3k
Let's Coding SwiftUI on iPad!
yutailang0119
1
530
Property Wrapperで遊ぼう / Play with Property Wrapper
yutailang0119
2
330
Back of First Screen AB test of Hatena Bookmark iOS app with Firebase AB Testing
yutailang0119
0
320
Other Decks in Programming
See All in Programming
How Android Uses Data Structures Behind The Scenes
l2hyunwoo
0
470
rage against annotate_predecessor
junk0612
0
170
複雑なドメインに挑む.pdf
yukisakai1225
5
1.2k
Deep Dive into Kotlin Flow
jmatsu
1
360
基礎から学ぶ大画面対応(Learning Large-Screen Support from the Ground Up)
tomoya0x00
0
3.2k
アルテニア コンサル/ITエンジニア向け 採用ピッチ資料
altenir
0
110
AIコーディングAgentとの向き合い方
eycjur
0
280
testingを眺める
matumoto
1
140
ProxyによるWindow間RPC機構の構築
syumai
3
1.2k
Android 16 × Jetpack Composeで縦書きテキストエディタを作ろう / Vertical Text Editor with Compose on Android 16
cc4966
2
260
個人軟體時代
ethanhuang13
0
330
Namespace and Its Future
tagomoris
6
700
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
3
54
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Building an army of robots
kneath
306
46k
GitHub's CSS Performance
jonrohan
1032
460k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.9k
Raft: Consensus for Rubyists
vanstee
140
7.1k
Being A Developer After 40
akosma
90
590k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
The Invisible Side of Design
smashingmag
301
51k
Bash Introduction
62gerente
615
210k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
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