Post

Replies

Boosts

Views

Activity

Reply to .backgroundTask in SwiftUI cannot compile
I have gotten mine to compile now by adding another intermediate view so that .backgroundTask can be on its own. I haven't checked the background task functionality yet, but at least it's compiling. Something like this: // MyApp.swift @main struct MyApp: App { var body: some Scene { WindowGroup { BackgroundTaskView() } .backgroundTask(.appRefresh("RUN_BACKGROUND")) { print("ran background") } } } and then // BackgroundTaskView.swift // This used to be in MyApp.swift but caused compilation error struct BackgroundTaskView: View { @StateObject var dataController: DataController init() { let dataController = DataController() _dataController = StateObject(wrappedValue: dataController) } var body: some View { ContentView() .environment(\.managedObjectContext, dataController.container.viewContext) .environmentObject(dataController) } }
Aug ’22