SingaporeKit

0.0.3

jiachenyee/SingaporeKit

What's New

Auto-Refreshing and other QOL improvements

2024-11-02T00:20:48Z

What's Changed

  • auto fetching by @jiachenyee in #2
  • conformance to identifiable for whenever possible
  • updated documentation

Full Changelog: 0.0.2...0.0.3

@Singapore

SingaporeKit makes it easy to use Singapore government data within your SwiftUI projects. Using the @Singapore property wrapper, you can retrieve real-time government data from data.gov.sg.

using @Singapore

Use the @Singapore property wrapper to retrieve any data.gov.sg real-time API value.

// Environment-Related
@Singapore(\.relativeHumidity) var relativeHumidity
@Singapore(\.twentyFourHourWeather) var twentyFourHourWeather
@Singapore(\.airTemperature) var airTemperature
@Singapore(\.rainfall) var rainfall
@Singapore(\.airQuality) var airQuality
@Singapore(\.uvIndex) var uvIndex
@Singapore(\.twoHourWeather) var twoHourWeather
@Singapore(\.fourDayForecast) var fourDayForecast

// Transport-Related
@Singapore(\.carparkAvailability) var carparkAvailability
@Singapore(\.trafficImages) var trafficImages
@Singapore(\.availableTaxis) var availableTaxis

You can also supply an option, such as a date, to retrieve data for a specific date / moment.

@Singapore(\.rainfall, options: .moment(.now.addingTimeInterval(-86400))) var uvIndex

Here's an example of how you can retrieve the value of a given property.

struct RelativeHumidityView: View {
    
    @Singapore(\.relativeHumidity) var relativeHumidity
    
    var body: some View {
        Group {
            switch relativeHumidity {
            case .loading, .none: ProgressView()
            case .failure: Text("Failed to fetch data")
            case .success(let relativeHumidity):
                List(relativeHumidity.stations) { station in
                    Section {
                        Map {
                            Marker("\(station.name)", coordinate: station.location.coordinate)
                        }
                        .frame(height: 100)
                        .listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
                        
                        Text(station.name)
                        
                        LabeledContent("Station ID") {
                            Text(station.id)
                        }
                        
                        if let latestReading = relativeHumidity.latestReading(for: station) {
                            Label("\(String(format: "%.1f", latestReading))%",
                                  systemImage: "humidity")
                        }
                    }
                }
            }
        }
        .navigationTitle("Locations")
    }
}

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu May 15 2025 05:48:28 GMT-0900 (Hawaii-Aleutian Daylight Time)