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.5k
バックポートして学ぶ新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
130
Apple Vision Pro購入RTA 1泊3日弾丸ハワイツアー / RTA: Purchase Apple Vision Pro in Hawaii
yutailang0119
0
1.4k
個人開発のたのしみ / Enjoying personal development
yutailang0119
0
900
Backport AsyncImage
yutailang0119
0
660
xcrun Essentials
yutailang0119
6
1.2k
Let's Coding SwiftUI on iPad!
yutailang0119
1
480
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
290
Lab of WWDC19
yutailang0119
1
500
Other Decks in Programming
See All in Programming
もう僕は OpenAPI を書きたくない
sgash708
5
1.8k
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
12
4.2k
CDK開発におけるコーディング規約の運用
yamanashi_ren01
2
150
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
270
How mixi2 Uses TiDB for SNS Scalability and Performance
kanmo
38
15k
Amazon S3 TablesとAmazon S3 Metadataを触ってみた / 20250201-jawsug-tochigi-s3tables-s3metadata
kasacchiful
0
170
Amazon Q Developer Proで効率化するAPI開発入門
seike460
PRO
0
120
Formの複雑さに立ち向かう
bmthd
1
870
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
7
880
PRレビューのお供にDanger
stoticdev
1
130
GoとPHPのインターフェイスの違い
shimabox
2
190
ML.NETで始める機械学習
ymd65536
0
130
Featured
See All Featured
KATA
mclloyd
29
14k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Faster Mobile Websites
deanohume
306
31k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
We Have a Design System, Now What?
morganepeng
51
7.4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
12
970
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