Post

Replies

Boosts

Views

Activity

How Come My WeatherKit Sample App Doesn't Work?
I have gone through several tutorials for WeatherKit. But my sample app doesn't return weather data. The following is a list of what I have. I've registered a Bundle ID for my sample app with the WeatherKit capability on. I've created a developer profile for my sample app. I've opened my Xcode project to make sure that the WeatherKit capability is enabled. I have run my sample app with an actual device. I have waited for more than 30 minutes for the service to kick in. It's been several days. The following is my code. import SwiftUI import CoreLocation import WeatherKit struct ContentView: View { @State var currentWeather: CurrentWeather? var body: some View { NavigationStack { List { Group { SampleCell(title: "Temperature", value: String(currentWeather?.apparentTemperature.value ?? 0.0) + "℃") SampleCell(title: "Cloud coverage", value: String(currentWeather?.cloudCover ?? 0.0)) SampleCell(title: "Weather condition", value: String(currentWeather?.condition.description ?? "")) SampleCell(title: "Dew point", value: String(currentWeather?.dewPoint.value ?? 0.0) + "℃") SampleCell(title: "Humidity", value: String(currentWeather?.humidity ?? 0.0)) SampleCell(title: "Pressure", value: String(currentWeather?.pressure.value ?? 0.0) + "mbar") SampleCell(title: "Pressure trend", value: String(currentWeather?.pressureTrend.description ?? "")) SampleCell(title: "Temperature", value: String(currentWeather?.temperature.value ?? 0.0) + "℃") SampleCell(title: "UV index", value: String(currentWeather?.uvIndex.value ?? 0)) SampleCell(title: "Visibility", value: String(currentWeather?.visibility.value ?? 0.0) + "m") } SampleCell(title: "Window direction", value: String(currentWeather?.wind.direction.value ?? 0.0) + "°") SampleCell(title: "Window speed", value: String(currentWeather?.wind.speed.value ?? 0.0) + "km/h") SampleCell(title: "Gust", value: String(currentWeather?.wind.gust?.value ?? 0.0) + "km/h") } .navigationTitle(Text("CurrentWeather")) .task { let service = WeatherService() let location = CLLocation( latitude: 35.467081, longitude: 139.620798 ) do { let weather = try await service.weather(for: location) currentWeather = weather.currentWeather } catch let error { print(error.localizedDescription) } } } } } struct SampleCell: View { var title: String var value: String var body: some View { VStack { HStack { Text(title) Spacer() Text(value) } } } } Yet, I constantly get the following warnings. 2023-11-29 09:33:46.504737+0900 WeatherCrazyMama[15279:9734572] [WeatherDataService] Aborting silent interpolation: no interpolator object; location=CLLocationCoordinate2D(latitude: 35.467081, longitude: 139.620798) 2023-11-29 09:33:47.900605+0900 WeatherCrazyMama[15279:9734577] [AuthService] Failed to generate jwt token for: com.apple.weatherkit.authservice with error: Error Domain=WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors Code=2 "(null)" 2023-11-29 09:33:47.989603+0900 WeatherCrazyMama[15279:9734572] [WeatherService] Encountered an error when fetching weather data subset; location=<+35.46708100,+139.62079800> +/- 0.00m (speed -1.00 mps / course -1.00) @ 2023/11/29 9:33:46 AM Japan Standard Time, error=WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors 2 Error Domain=WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors Code=2 "(null)" The operation couldn’t be completed. (WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors error 2.) What am I doing wrong? Thanks.
2
1
1.5k
Jan ’24
Can SwiftUI View Receive a Call When Window Will Close?
I have an NSStatusBar application. This is my first in SwiftUI. And I need to know when the window is closed so that I can disable some of menu commands. I can use NSWindowDelegate with AppDelegate as follows. import SwiftUI @main struct SomeApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @StateObject private var menuViewModel = MenuViewModel() var body: some Scene { WindowGroup { ContentView() .environmentObject(menuViewModel) } } } class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate { private var menuViewModel = MenuViewModel() func applicationDidFinishLaunching(_ notification: Notification) { if let window = NSApplication.shared.windows.first { window.setIsVisible(false) window.delegate = self } } func windowWillClose(_ notification: Notification) { menuViewModel.windowClosed = true } } When the window will close, MenuViewModel (ObservableObject) will receive a call, which I want my ContentView to receive. But, so far, it won't. import SwiftUI struct ContentView: View { var body: some View { ZStack { ... ... } .onReceive(statusBarViewModel.$windowClosed) { result in // never called... } } } Can a SwiftUI View receive a call somehow when its window closes? Muchos thankos.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
3
1
558
Jun ’25
Too Complex To Check Code in Reasonable Time?
Again, I have a vertical stack of horizontal stacks of buttons as follows. import SwiftUI struct ContentView: View { &#9;&#9;@State private var eventPresented = Bool() &#9;&#9;@State private var selectedEventIndex = Int() &#9;&#9;@State private var monthSelection = Int() &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;VStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((0...6), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;index in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[index] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;eventPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;selectedEventIndex = index + 1 - self.weekIndex &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(titleColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.overlay(Text(eventNumbers[index] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: shadowColors[index], radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.sheet(isPresented: $eventPresented) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex, monthFromParent: self.$monthSelection) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(alignment: .top, spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((35...36), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;index in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[index] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;eventPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;selectedEventIndex = index + 1 - self.weekIndex &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(titleColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.overlay(Text(eventNumbers[index] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: shadowColors[index], radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.sheet(isPresented: $eventPresented) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex, monthFromParent: self.$monthSelection) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 336.0, height: 48.0, alignment: .leading) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} } And I want to send a few variables to EventView when the user clicks on a button. struct EventView: View { &#9;&#9;@Binding var eventVisible: Bool &#9;&#9;@Binding var dayFromParent: Int &#9;&#9;@Binding var monthFromParent: Int &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;Text("Window sheet.") &#9;&#9;&#9;&#9;&#9;&#9;Button("OK") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.eventVisible = false &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("month from parent: \(monthFromParent)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("day from parent: \(dayFromParent)") &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;.frame(width: 240, height: 180) &#9;&#9;} } If I just want to send two variables to it, EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex) the compiler didn't complain. For the third variable, it says SwiftUI the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions I know what it means. Some say it could resolve the issue by making the data types of variables clearer. Others say you could use a function to return a variable for a somewhat complex algebra equation. But what can I do in my case? Does anybody have any suggestions? Thank you
6
0
807
Jan ’21