Open fatbobman opened 8 months ago
太棒了👍
@Observable 修饰的viewModel 直接标注sendable 可行吗,感觉标mainActor 还挺麻烦的
你里面提到的"PasteButton(payloadType: String.self){ str in // Call to main actor-isolated initializer 'init(payloadType:onPaste:)' in a synchronous nonisolated context",这个在Xcode 16中并没有报错啊,我确定开启了Swift 6
@skywalkerlw Xcode 16 已经做了调整,文章中有提到
SwiftUI 视图与 MainActor
越来越多的开发者开始尝试开启并发严格检查选项,为 Swift 6 的到来做准备。在收到的警告和错误中,有一部分是与 SwiftUI 的视图有关,其中很多都是由于开发者没有正确的理解和使用
@MainActor
造成的。本文将聊聊@MainActor
的含义,以及在 SwiftUI 的视图中应用@MainActor
的技巧和注意事项。SwiftUI Views and @MainActor
An increasing number of developers are starting to enable strict concurrency checks in preparation for the arrival of Swift 6. Among the warnings and errors received, a portion relates to SwiftUI views, many of which stem from developers not correctly understanding or using
@MainActor
. This article will discuss the meaning of@MainActor
, as well as tips and considerations for applying@MainActor
within SwiftUI views.