WeatherKit
Fetch current conditions, hourly and daily forecasts, weather alerts, and
historical statistics using WeatherService. Display required Apple Weather attribution.
Contents
- Setup
- Fetching Current Weather
- Forecasts
- Weather Alerts
- Selective Queries
- Context Queries
- Attribution
- Availability
- Common Mistakes
- Review Checklist
- References
Setup
Project Configuration
- Enable the WeatherKit capability in Xcode (adds the entitlement)
- Enable WeatherKit for your App ID in the Apple Developer portal
- Add
NSLocationWhenInUseUsageDescriptionto Info.plist if using device location - WeatherKit requires an active Apple Developer Program membership
Import
Creating the Service
Use the shared singleton or create an instance. WeatherService conforms to
Sendable; keep app cache and UI state isolated separately.
Fetching Current Weather
Fetch current conditions for a location. Returns a Weather object with all
available datasets.
WeatherKit temperatures are Measurement<UnitTemperature> values; display them
with .formatted() so units and number formatting follow the user's locale.
Forecasts
Hourly Forecast
Returns 25 contiguous hours starting from the current hour by default.
Daily Forecast
Returns 10 contiguous days starting from the current day by default.
Custom Date Range
Request forecasts for specific date ranges using WeatherQuery.
Daily and hourly date-range queries use an inclusive startDate and exclusive
endDate. They can include historical data from August 1, 2021. Forecasts are
available up to 10 days in the future; each request returns at most 10 daily
forecast days or about 240 hourly forecast hours.
For tomorrow-specific guidance, request the local tomorrow day interval rather than using minute forecasts:
Weather Alerts
Fetch active weather alerts for a location. Alerts include severity, summary, and affected regions.
For alert dashboards, name WeatherAvailability explicitly when discussing
support checks: it exposes alertAvailability and minuteAvailability only,
not a broad availability matrix for current, hourly, or daily weather.
Selective Queries
Fetch only the datasets you need to minimize API usage and response size. Each
WeatherQuery type maps to one dataset.
Single Dataset
Multiple Datasets
Minute Forecast
Available in limited regions. Returns precipitation forecasts at minute granularity for the next hour.
Available Query Types
Context Queries
For "unusual tomorrow" or "what is changing?" features on iOS 18+, request the
optional .changes and .historicalComparisons results together: the first
reports significant upcoming changes and the second provides historical context.
Historical summaries and statistics use WeatherService methods rather than
WeatherQuery. Load references/weatherkit-patterns.md [blocked]
for their tuple ordering, APIs, and statistics-specific properties.
Attribution
Apple requires apps using WeatherKit to display attribution. This is a legal requirement.
Fetching Attribution
Load references/weatherkit-patterns.md [blocked] for the complete SwiftUI attribution view and cache integration.
Attribution Properties
Availability
Check whether weather alerts or minute forecast data are available for a
location. WeatherAvailability reports only alert and minute availability;
other datasets, such as current weather, are expected to be supported for
geographic locations.
Common Mistakes
DON'T: Ship without Apple Weather attribution
Display the appropriate Apple Weather mark and link legalPageURL wherever WeatherKit data appears; use legalAttributionText only when the legal page cannot be shown.
DON'T: Fetch all datasets when you only need current conditions
Each dataset query counts against your API quota. Use the selective query shown in Selective Queries and fetch only what the UI displays.
DON'T: Ignore minute forecast unavailability
Minute forecasts are optional in unsupported regions. Check availability and
handle the nil result instead of force-unwrapping it.
DON'T: Forget the WeatherKit entitlement
Without the capability enabled, WeatherService calls throw at runtime.
DON'T: Make repeated requests without caching
WeatherKit models include metadata.expirationDate. Cache responses until that
expiration instead of inventing a fixed interval or fetching on every view
appearance. Let a model or cache own loadIfNeeded; the complete actor pattern
is in references/weatherkit-patterns.md [blocked].
Review Checklist
- WeatherKit capability enabled in Xcode and Apple Developer portal
- Active Apple Developer Program membership (required for WeatherKit)
- Apple Weather attribution displayed wherever weather data appears
- Attribution mark uses correct color scheme variant (light/dark)
- Legal attribution page linked or
legalAttributionTextdisplayed - Only needed
WeatherQuerydatasets fetched (not fullweather(for:)when unnecessary) - Minute forecast handled as optional (nil in unsupported regions)
- Weather alerts checked for nil before iteration
- Alert detail links use non-optional
detailsURL; optionalregionis nil-safe - Responses cached until each model's
metadata.expirationDate -
WeatherAvailabilityused for alert/minute availability, not as a broad support matrix - Location permission requested before passing
CLLocationto service - Temperature and measurements formatted with
Measurement.formatted()for locale
References
- Extended patterns (SwiftUI dashboard, charts integration, historical statistics): references/weatherkit-patterns.md [blocked]
- WeatherKit framework
- WeatherService
- WeatherAttribution
- WeatherQuery
- WeatherQuery.daily(startDate:endDate:)
- WeatherQuery.hourly(startDate:endDate:)
- CurrentWeather
- CurrentWeather.temperature
- Measurement.formatted()
- Forecast
- HourWeather
- DayWeather
- WeatherAlert
- WeatherAvailability
- WeatherMetadata.expirationDate
- WeatherQuery.changes
- WeatherQuery.historicalComparisons
- WeatherKit updates
- Bring context to today's weather
- Fetching weather forecasts with WeatherKit


