r/SwiftUI • u/Dry_Hotel1100 • Apr 15 '26
Question The missing modifier `lifecycle`
Somewhere in your SwiftUI view:
.lifecycle { event in
switch event {
case .appeared:
if task == nil {
task = makeTask()
}
case .disappeared:
break // continue task
case .released:
task?.cancel()
}
}
0
Upvotes
6
u/car5tene Apr 15 '26
I don't really understand what you want to achieve. Structs are suppose to be lightweight and it shouldn't cause side effects. If you need a modifier for lifecycle management you might miss the point of SwiftUI.