最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

concurrency - Difference Between @MainActor func and Task { @MainActor in } in Swift 6 - Stack Overflow

programmeradmin1浏览0评论

I have a class MyUIClass that is @MainActor isolated:

@MainActor
class MyUIClass {
    func show(object: Any?) {}
}

To use the show function, it needs to be accessed within the MainActor context:

class Santa {
    @MainActor
    func present1(gift: Any?) {
        MyUIClass().show(object: gift) // ✅
    }
    
    func present2(gift: Any?) {
        Task { @MainActor in
            MyUIClass().show(object: gift) // 
发布评论

评论列表(0)

  1. 暂无评论