Post

Replies

Boosts

Views

Activity

How to await for async stuff within a moc.perform block
I want to implement this pattern in my app: let moc = ...newBackgroundContext() try await moc.perform { // test for existence of a specific object in the moc if !objectExists { let apiObject = await api.fetchObjectFromNetwork() // create managed object from apiObject try moc.save() } } Unfortunately, I am unable to await my network call because the moc.perform block is not async. So far, I've come up with this solution: let moc = ...newBackgroundContext() try await moc.perform { // test for existence of a specific object in the moc if !objectExists { Task { let apiObject = await api.fetchObjectFromNetwork() try await moc.perform { // create managed object from apiObject try moc.save() } } } } But it doesn't feel quite right. What do you think? Am I on the right track, or am I introducing unneeded complexity?
0
0
494
Aug ’21
How to dismiss a TipView on tvOS
I have added a "welcome" tip to my SwiftUI app, which only appears on the main screen the first time the app is launched. On macOS and iOS, the TipView has an X button that lets the user dismiss the tip. However, on tvOS there is no such button, and I cannot figure out how to dismiss the tip at all. Using the remote, I am unable to navigate to the tip and highlight it so I can click it to dismiss. Pressing the Home remote button while the tip is displayed has no effect other than closing my app and going back to the tvOS launch screen. Am I missing something? struct ContentView: View { @Environment(TempestDataProvider.self) private var dataProvider @State private var welcomeTip = WelcomeTip() var body: some View { VStack { Grid { GridRow { TemperatureMetricBox(alignment: .leading, backgroundStyle: nil, bottomPadding: true) WindMetricBox(alignment: .trailing, backgroundStyle: nil, bottomPadding: true) } GridRow { HumidityMetricBox(alignment: .leading, backgroundStyle: nil, bottomPadding: true) PressureMetricBox(alignment: .trailing, backgroundStyle: nil, bottomPadding: true) } GridRow { RainMetricBox(alignment: .leading, backgroundStyle: nil, bottomPadding: true) SunMetricBox(alignment: .trailing, backgroundStyle: nil, bottomPadding: true) } GridRow { LightningMetricBox(alignment: .leading, backgroundStyle: nil, bottomPadding: true) MetricBox(alignment: .trailing, systemImageName: "sensor", backgroundStyle: nil, bottomPadding: true) { IndicatorLightPanel() } } } .fixedSize(horizontal: false, vertical: true) Spacer() TipView(welcomeTip) StatusBar() } } }
1
0
162
Oct ’24