Overview
PollenService is a Swift actor that fetches pollen data from the Google Pollen API through a backend proxy. It provides detailed pollen information including pollen types (grass, tree, weed) and specific plant data with health recommendations.
BreezeApp/Services/PollenService.swift:4
Actor Isolation
This service is implemented as an actor to ensure thread-safe access to its methods and properties. All async methods are actor-isolated and can be safely called from any context.Shared Instance
Backend Proxy
The service uses a backend proxy URL instead of calling the Google Pollen API directly:Methods
fetchPollen
Fetch comprehensive pollen data for a specific location.Double
required
The latitude of the location to fetch pollen data for
Double
required
The longitude of the location to fetch pollen data for
[PollenItem] - An array of pollen items containing:
- Pollen Types: General categories (Grass, Tree, Weed) with index values and categories
- Specific Plants: Detailed information about individual plants including:
- Display name and code
- Index value and category (Low, Moderate, High, Very High)
- Plant description with image URL
- Family, season, and appearance information
- Health recommendations
URLError.badURL- If the URL cannot be constructedURLError.badServerResponse- If the server returns a non-200 status codeDecodingError- If the response cannot be decoded
- Pollen Types: Extracts general pollen type information (grass, tree, weed)
- Plant Information: Extracts specific plant data with detailed descriptions
Usage Examples
Basic Usage
Separating Pollen Types and Plants
Display in SwiftUI
Source Code
Special Handling
GRAMINALES Plant
The service includes special handling for the “GRAMINALES” plant code to ensure proper display formatting:Data Structure
The returnedPollenItem objects distinguish between general pollen types and specific plants using the isPlant boolean:
-
isPlant: false: General pollen type (Grass, Tree, Weed)- No image, family, season, or appearance data
- May include health recommendations
-
isPlant: true: Specific plant species- Includes detailed plant description
- Image URL for visual identification
- Family, season, and appearance information
- Plant-specific health recommendations