Skip to main content

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.
Source: 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

A singleton instance of the service that can be accessed throughout the application.

Backend Proxy

The service uses a backend proxy URL instead of calling the Google Pollen API directly:
This proxy handles API authentication and rate limiting, ensuring secure access to the Google Pollen API.

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
Returns: [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
Throws:
  • URLError.badURL - If the URL cannot be constructed
  • URLError.badServerResponse - If the server returns a non-200 status code
  • DecodingError - If the response cannot be decoded
Implementation Details: The method processes the API response in two stages:
  1. Pollen Types: Extracts general pollen type information (grass, tree, weed)
  2. 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 returned PollenItem 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

See Also