Compose SwiftUIv0.4.0
esc
GuideAPIGitHub
View modifier

task(_:)

Starts asynchronous work when the view appears and cancels it when it disappears.

iOS 17.0+macOS 14.0+tvOS 17.0+watchOS 10.0+
fun Modifier.task(name: String? = null, file: String? = null, line: Int? = null, action: () -> Unit): Modifier

Overview

In Kotlin, a LaunchedEffect in the composable usually expresses the same thing.

Modifier.task(action = { })

This is the Kotlin form of SwiftUI View.task(name:priority:file:line:_:): SwiftUI documentation. In Swift it reads:

@export(implementation) nonisolated func task(name: String? = nil, priority: TaskPriority = .userInitiated, file: String = #fileID, line: Int = #line, _ action: sending @escaping @isolated(any) () async -> Void) -> some View

Topics

Overloads

fun Modifier.task(id: Any, name: String? = null, file: String? = null, line: Int? = null, action: () -> Unit): Modifier
SwiftUI View.task(id:name:priority:file:line:_:)
fun Modifier.task(name: String? = null, file: String? = null, line: Int? = null, action: () -> Unit): Modifier
SwiftUI View.task(name:priority:file:line:_:)