Share
Embed
Road to Swift 6
yuki shinohara
July 16, 2024
Transcript
38 slides
-
Introduction Name: 篠原 裕貴 Work: 株式会社マネーフォワード > マネーフォワードビジ ネスカンパニー >
ERP開発本部 > 福岡第一開発部 > Warriorグループ > モバイルアプリ開発チーム Career: 公務員 > ワーホリ > 英会話講師 > iOSエンジニア Hobbies: ランニング、柴犬、アニメ -
もうすぐSwift 6がやってくる ❏ 7/10時点でのSwift最新バージョン 5.10.1 ❏ Xcode16 betaをインストールするとSwift 6を使うことができる ❏
データ競合がなくなってアプリのパフォーマンスが上がる -
もうすぐSwift 6がやってくる ❏ 7/10時点でのSwift最新バージョン 5.10.1 ❏ Xcode16 betaをインストールするとSwift 6を使うことができる ❏
データ競合がなくなってアプリのパフォーマンスが上がる 今のコードベースだ とBuildしない可能 性が💥 -
もうすぐSwift 6がやってくる ❏ 7/10時点でのSwift最新バージョン 5.10.1 ❏ Xcode16 betaをインストールするとSwift 6を使うことができる ❏
データ競合がなくなってアプリのパフォーマンスが上がる -
もうすぐSwift 6がやってくる ❏ 7/10時点でのSwift最新バージョン 5.10.1 ❏ Xcode16 betaをインストールするとSwift 6を使うことができる ❏
データ競合がなくなってアプリのパフォーマンスが上がる データ競合を起こす可能性の あるコードは全てビルドエラー になってしまう -
Road to Swift 6: アジェンダ ❏ Concurrency ❏ Actor ❏
Steps to enable Swift 6 mode ❏ Tips -
With Concurrency ❏ 例) APIのリクエストをawaitで実行する ❏ 上から下に読める ❏ idsを取得→imagesを取得→showImagesを実行 awaitの処理が終わるまで
処理が次に進まない (ブ ロックするわけではない ) -
Strict Concurrency Checking ❏ Start to emit warning about code
that is not able to conform to concurrency safe -
❏ グローバル変数 ❏ どこからでも読み書きできる → データ競合🔥 Var 'XXX' is not
concurrency-safe because it is non-isolated global shared mutable state; WWDC24. 「Swift 6へのアプリの移行」 . https://developer.apple.com/jp/videos/play/wwdc2024/10169/, (参照 2024-7-11) -
❏ グローバル変数 ❏ 定数にする: var → let ❏ @MainActorを付与する ❏
nonisolated(unsafe)を付与する Var 'XXX' is not concurrency-safe because it is non-isolated global shared mutable state; WWDC24. 「Swift 6へのアプリの移行」 . https://developer.apple.com/jp/videos/play/wwdc2024/10169/, (参照 2024-7-11) -
❏ Call a main actor isolated class method from sync
nonisolated context ❏ Concurrencyを使えるようにasyncを追加する or Task で囲む ❏ @MainActorをメソッドに付与する ❏ 呼び出し側もMainActorで呼び出す必要がある Call to actor-isolated instance method in a synchronous actor-isolated context WWDC24. 「Swift 6へのアプリの移行」 . https://developer.apple.com/jp/videos/play/wwdc2024/10169/, (参照 2024-7-11) -
Call to actor-isolated instance method in a synchronous actor-isolated context
❏ Call a main actor isolated class method from sync nonisolated context ❏ Concurrencyを使えるようにasyncを追加する or Task で囲む ❏ @MainActorをメソッドに付与する ❏ 呼び出し側もMainActorで呼び出す必要がある WWDC24. 「Swift 6へのアプリの移行」 . https://developer.apple.com/jp/videos/play/wwdc2024/10169/, (参照 2024-7-11) -
❏ Needs to be called from methods on the main
actor ❏ ContentView: MainActor ❏ Extension: Call to actor-isolated instance method in a synchronous actor-isolated context WWDC24. 「Swift 6へのアプリの移行」 . https://developer.apple.com/jp/videos/play/wwdc2024/10169/, (参照 2024-7-11) -
❏ Needs to be called from methods on the main
actor ❏ ContentView: MainActor ❏ Extension: Call to actor-isolated instance method in a synchronous actor-isolated context WWDC24. 「Swift 6へのアプリの移行」 . https://developer.apple.com/jp/videos/play/wwdc2024/10169/, (参照 2024-7-11) -
MainActor-isolated instance method “XXX” cannot be used to satisfy noisolated
protocol requirement ❏ nonisolatedをメソッドに付与する ❏ アクターからの孤立ルールから除外する (よくない) →仕方ないケース ❏ @MainActorをDelegateにつける WWDC24. 「Swift 6へのアプリの移行」 . https://developer.apple.com/jp/videos/play/wwdc2024/10169/, (参照 2024-7-11) -
❏ @preconcurrencyだけでok MainActor-isolated instance method “XXX” cannot be used to
satisfy noisolated protocol requirement WWDC24. 「Swift 6へのアプリの移行」 . https://developer.apple.com/jp/videos/play/wwdc2024/10169/, (参照 2024-7-11) -
Callback and completionHandler ❏ Not mentioned about the queue: non-isolated.
Cannot access the isolated data ❏ Mentioned: guaranteed WWDC24. 「Swift 6へのアプリの移行」 . https://developer.apple.com/jp/videos/play/wwdc2024/10169/, (参照 2024-7-11)