當初 Swift 5 -> Swift 6 時,
開發者需面臨必加的3樣東西
1.nonisolated (不是在當前的context,通常為非MainThread場景)
2.@MainActor (標記為 回來的context為MainThread),
3.MainActor.assumeIsolated { // 放置必需在MainThread中執行的程式的同步方法,缺點是進來的如果 非MainThread 則會 Crash }
而Swift 6.2 在新開的Xcode專案中,預設開啟,舊專案需要手動調整
預設在MainActor(Main thread上),在需要background thread的時候,將function標記成 @concurrent
心得:
更加友善的async / await,類似C#
更詳細的參考資料:
https://fatbobman.com/zh/weekly/issue-103/
https://www.swift.org/blog/swift-6.2-released/?utm_source=Fatbobman%20Blog&utm_medium=web
https://www.youtube.com/shorts/WvYpGO65_ts
https://www.donnywals.com/should-you-opt-in-to-swift-6-2s-main-actor-isolation/
文章標籤
全站熱搜
