MainActor

hankyulee·2022년 5월 20일
0

SwiftUI

목록 보기
2/4

Dispatch UI updates on the main queue automatically using MainActor

swift5.5.
when using Swift’s new concurrency system : await/async

But what if we’re instead working on a completely custom type that we’d also like to gain the above kind of capability? For example, when implementing an ObservableObject that’s used within a SwiftUI view, we need to make sure to only assign its @Published-marked properties on the main queue, so wouldn’t it be great if we could also leverage the MainActor in those cases as well?

@MainActor class ListViewModel: ObservableObject

all of this only works when we’re using Swift’s new concurrency system

0개의 댓글