티스토리 뷰

📱 SwiftUI

Task & await & async & @MainActor

James Wetzel 2022. 7. 15. 15:28
728x90
반응형

 

목차

  • Task
  • await
  • async
  • mainActor

 

Task & await & async & @MainActor

init() {
    Task {
        await handleCameraPreviews()
    }
}

func handleCameraPreviews() async {
    let imageStream = camera.previewStream
    .map { $0.image }

    for await image in imageStream {
        Task { @MainActor in
        	viewfinderImage = image
        }
    }
}
728x90
반응형