'Swift UIApplication not in scope

I want to change isIdleTimerDisabled when a specific view appears. In SwiftUI I use .onAppear { UIApplication.shared.isIdleTimerDisabled = true } .onDisappear { UIApplication.shared.isIdleTimerDisabled = false } but even with import UIKit I get the warning "Cannot find 'UIApplication' in scope". How can I fix that? I didn't find a solution after searching for more than an hour.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source