Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计通过

weatherkitweatherkit 命令行

Agent Skill

weatherkit 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

26,136

周安装

1,093

GitHub Stars

469

下载量

9,152
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:weatherkit(weatherkit 命令行)
来源仓库:https://github.com/dpearson2699/swift-ios-skills
仓库路径:skills/weatherkit
安装命令:
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill weatherkit
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill weatherkit

简介

weatherkit 通过 WeatherService 获取天气数据,包括实况、预报与历史统计信息。

  • 适用于出行、农业或 IoT 类应用集成气象服务,需显示 Apple 官方 attribution。
  • 支持选择性查询与设备位置自动获取,满足低功耗与精准定位需求。
  • 需在开发者门户启用 WeatherKit 权限,并配置 Info.plist 相关 usage description。
  • weatherkit 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

WeatherKit

Fetch current conditions, hourly and daily forecasts, weather alerts, and historical statistics using WeatherService. Display required Apple Weather attribution. Targets Swift 6.3 / iOS 26+.

Contents

Setup

Project Configuration

  1. Enable the WeatherKit capability in Xcode (adds the entitlement)
  2. Enable WeatherKit for your App ID in the Apple Developer portal
  3. Add NSLocationWhenInUseUsageDescription to Info.plist if using device location
  4. WeatherKit requires an active Apple Developer Program membership

Import

import WeatherKit
import CoreLocation

Creating the Service

Use the shared singleton or create an instance. The service is Sendable and thread-safe.

let weatherService = WeatherService.shared
// or
let weatherService = WeatherService()

Fetching Current Weather

Fetch current conditions for a location. Returns a Weather object with all available datasets.

func fetchCurrentWeather(for location: CLLocation) async throws -> CurrentWeather {
    let weather = try await weatherService.weather(for: location)
    return weather.currentWeather
}

// Using the result
func displayCurrent(_ current: CurrentWeather) {
    let temp = current.temperature  // Measurement<UnitTemperature>
    let condition = current.condition  // WeatherCondition enum
    let symbol = current.symbolName  // SF Symbol name
    let humidity = current.humidity  // Double (0-1)
    let wind = current.wind  // Wind (speed, direction, gust)
    let uvIndex = current.uvIndex  // UVIndex

    print("\(condition): \(temp.formatted())")
}

Forecasts

Hourly Forecast

Returns 25 contiguous hours starting from the current hour by default.

func fetchHourlyForecast(for location: CLLocation) async throws -> Forecast<HourWeather> {
    let weather = try await weatherService.weather(for: location)
    return weather.hourlyForecast
}

// Iterate hours
for hour in hourlyForecast {
    print("\(hour.date): \(hour.temperature.formatted()), \(hour.condition)")
}

Daily Forecast

Returns 10 contiguous days starting from the current day by default.

func fetchDailyForecast(for location: CLLocation) async throws -> Forecast<DayWeather> {
    let weather = try await weatherService.weather(for: location)
    return weather.dailyForecast
}

// Iterate days
for day in dailyForecast {
    print("\(day.date): \(day.lowTemperature.formatted()) - \(day.highTemperature.formatted())")
    print("  Condition: \(day.condition), Precipitation: \(day.precipitationChance)")
}

Custom Date Range

Request forecasts for specific date ranges using WeatherQuery.

func fetchExtendedForecast(for location: CLLocation) async throws -> Forecast<DayWeather> {
    let startDate = Date.now
    let endDate = Calendar.current.date(byAdding: .day, value: 10, to: startDate)!

    let forecast = try await weatherService.weather(
        for: location,
        including: .daily(startDate: startDate, endDate: endDate)
    )
    return forecast
}

Weather Alerts

Fetch active weather alerts for a location. Alerts include severity, summary, and affected regions.

func fetchAlerts(for location: CLLocation) async throws -> [WeatherAlert]? {
    let weather = try await weatherService.weather(for: location)
    return weather.weatherAlerts
}

// Process alerts
if let alerts = weatherAlerts {
    for alert in alerts {
        print("Alert: \(alert.summary)")
        print("Severity: \(alert.severity)")
        print("Region: \(alert.region)")
        if let detailsURL = alert.detailsURL {
            // Link to full alert details
        }
    }
}

Selective Queries

Fetch only the datasets you need to minimize API usage and response size. Each WeatherQuery type maps to one dataset.

Single Dataset

let current = try await weatherService.weather(
    for: location,
    including: .current
)
// current is CurrentWeather

Multiple Datasets

let (current, hourly, daily) = try await weatherService.weather(
    for: location,
    including: .current, .hourly, .daily
)
// current: CurrentWeather, hourly: Forecast<HourWeather>, daily: Forecast<DayWeather>

Minute Forecast

Available in limited regions. Returns precipitation forecasts at minute granularity for the next hour.

let minuteForecast = try await weatherService.weather(
    for: location,
    including: .minute
)
// minuteForecast: Forecast<MinuteWeather>?  (nil if unavailable)

Available Query Types

QueryReturn TypeDescription
.currentCurrentWeatherCurrent observed conditions
.hourlyForecast<HourWeather>25 hours from current hour
.dailyForecast<DayWeather>10 days from today
.minuteForecast<MinuteWeather>?Next-hour precipitation (limited regions)
.alerts[WeatherAlert]?Active weather alerts
.availabilityWeatherAvailabilityDataset availability for location

Attribution

Apple requires apps using WeatherKit to display attribution. This is a legal requirement.

Fetching Attribution

func fetchAttribution() async throws -> WeatherAttribution {
    return try await weatherService.attribution
}

Displaying Attribution in SwiftUI

import SwiftUI
import WeatherKit

struct WeatherAttributionView: View {
    let attribution: WeatherAttribution
    @Environment(\.colorScheme) private var colorScheme

    var body: some View {
        VStack {
            // Display the Apple Weather mark
            AsyncImage(url: markURL) { image in
                image
                    .resizable()
                    .scaledToFit()
                    .frame(height: 20)
            } placeholder: {
                EmptyView()
            }

            // Link to the legal attribution page
            Link("Weather data sources", destination: attribution.legalPageURL)
                .font(.caption2)
                .foregroundStyle(.secondary)
        }
    }

    private var markURL: URL {
        colorScheme == .dark
            ? attribution.combinedMarkDarkURL
            : attribution.combinedMarkLightURL
    }
}

Attribution Properties

PropertyUse
combinedMarkLightURLApple Weather mark for light backgrounds
combinedMarkDarkURLApple Weather mark for dark backgrounds
squareMarkURLSquare Apple Weather logo
legalPageURLURL to the legal attribution web page
legalAttributionTextText alternative when a web view is not feasible
serviceNameWeather data provider name

Availability

Check which weather datasets are available for a given location. Not all datasets are available in all countries.

func checkAvailability(for location: CLLocation) async throws {
    let availability = try await weatherService.weather(
        for: location,
        including: .availability
    )

    // Check specific dataset availability
    if availability.alertAvailability == .available {
        // Safe to fetch alerts
    }

    if availability.minuteAvailability == .available {
        // Minute forecast available for this region
    }
}

Common Mistakes

DON'T: Ship without Apple Weather attribution

Omitting attribution violates the WeatherKit terms of service and risks App Review rejection.

// WRONG: Show weather data without attribution
VStack {
    Text("72F, Sunny")
}

// CORRECT: Always include attribution
VStack {
    Text("72F, Sunny")
    WeatherAttributionView(attribution: attribution)
}

DON'T: Fetch all datasets when you only need current conditions

Each dataset query counts against your API quota. Fetch only what you display.

// WRONG: Fetches everything
let weather = try await weatherService.weather(for: location)
let temp = weather.currentWeather.temperature

// CORRECT: Fetch only current conditions
let current = try await weatherService.weather(
    for: location,
    including: .current
)
let temp = current.temperature

DON'T: Ignore minute forecast unavailability

Minute forecasts return nil in unsupported regions. Force-unwrapping crashes.

// WRONG: Force-unwrap minute forecast
let minutes = try await weatherService.weather(for: location, including: .minute)
for m in minutes! { ... } // Crash in unsupported regions

// CORRECT: Handle nil
if let minutes = try await weatherService.weather(for: location, including: .minute) {
    for m in minutes { ... }
} else {
    // Minute forecast not available for this region
}

DON'T: Forget the WeatherKit entitlement

Without the capability enabled, WeatherService calls throw at runtime.

// WRONG: No WeatherKit capability configured
let weather = try await weatherService.weather(for: location) // Throws

// CORRECT: Enable WeatherKit in Xcode Signing & Capabilities
// and in the Apple Developer portal for your App ID

DON'T: Make repeated requests without caching

Weather data updates every few minutes, not every second. Cache responses to stay within API quotas and improve performance.

// WRONG: Fetch on every view appearance
.task {
    let weather = try? await fetchWeather()
}

// CORRECT: Cache with a staleness interval
actor WeatherCache {
    private var cached: CurrentWeather?
    private var lastFetch: Date?

    func current(for location: CLLocation) async throws -> CurrentWeather {
        if let cached, let lastFetch,
           Date.now.timeIntervalSince(lastFetch) < 600 {
            return cached
        }
        let fresh = try await WeatherService.shared.weather(
            for: location, including: .current
        )
        cached = fresh
        lastFetch = .now
        return fresh
    }
}

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 legalAttributionText displayed
  • Only needed WeatherQuery datasets fetched (not full weather(for:) when unnecessary)
  • Minute forecast handled as optional (nil in unsupported regions)
  • Weather alerts checked for nil before iteration
  • Responses cached with a reasonable staleness interval (5-15 minutes)
  • WeatherAvailability checked before fetching region-limited datasets
  • Location permission requested before passing CLLocation to service
  • Temperature and measurements formatted with Measurement.formatted() for locale

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.88%
按下载量换算3,284

Claude

27.27%
按下载量换算2,496

Cursor

18.09%
按下载量换算1,656

Gemini CLI

9.28%
按下载量换算849

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills