SwiftOpenWeatherMapAPI 0.0.8

SwiftOpenWeatherMapAPI 0.0.8

Filippo Tosetto 维护。



 
依赖项
Alamofire~> 2.0
SwiftyJSON~> 2.3.0
 

  • Filippo Tosetto

Swift Open Weather Map API

Swift Open Weather Map API 是对 OpenWeatherAPI 的封装

需求

  • iOS 8.0+ / Mac OS X 10.9+
  • Xcode 7

安装

初始化

包含头文件

import SwiftOpenWeatherMapAPI

设置 api

// Setup weather api
let weatherAPI = WAPIManager(apiKey: "YOUR_API_KEY")

// Setup weather api with temperature format
let weatherAPI = WAPIManager(apiKey: "YOUR_API_KEY", temperatureFormat: .Celsius)

// Setup weather api with temperature format and language
let weatherAPI = WAPIManager(apiKey: "YOUR_API_KEY", temperatureFormat: .Celsius, lang: .English)

获取数据

目前,这个 api 只是 http-api 的简单封装。

weatherAPI.currentWeatherByCityNameAsJson("London") { (json) -> Void in
    //Do something with the data
}

结果是一个从使用 SwiftyJSON 映射 api 数据得来的 JSON 结构体

用法

目前有以下方法可用

当前天气

按城市名称获取当前天气

public func currentWeatherByCityNameAsJson(cityName: String, data: (JSON) -> Void)

按坐标获取当前天气

public func currentWeatherByCoordinatesAsJson(coordinates: CLLocationCoordinate2D, data: (JSON) -> Void)

预报(3 小时间隔)

按城市名称获取预报

public func forecastWeatherByCityNameAsJson(cityName: String, data: (JSON) -> Void)

按坐标获取预报

public func forecastWeatherByCoordinatesAsJson(coordinates: CLLocationCoordinate2D, data: (JSON) -> Void)

每日预报

按城市名称获取每日预报

public func dailyForecastWeatherByCityNameAsJson(cityName: String, data: (JSON) -> Void)

按坐标获取每日预报

public func dailyForecastWeatherByCoordinatesAsJson(coordinates: CLLocationCoordinate2D, data: (JSON) -> Void)

历史数据

按城市名称获取历史数据

public func historicDataByCityNameAsJson(cityName: String, start: NSDate, end: NSDate?, data: (JSON) -> Void)

按坐标获取历史数据

public func historicDataByCoordinatesAsJson(coordinates: CLLocationCoordinate2D, start: NSDate, end: NSDate?, data: (JSON) -> Void)