HJWeather 0.2.1

HJWeather 0.2.1

HeeJung Kim维护。



 
依赖项
Alamofire>= 0
SwiftyJSON>= 0
 

HJWeather 0.2.1

  • HJKim95

HJWeather

HJWeather_main Languages
CI Status Version License Platform

示例

要运行示例项目,请克隆仓库,并且在Example目录中首先运行pod install

要求

  • iOS 10.0+
  • Xcode 11+
  • Swift 5.0+

安装

  • 手动
  • Cocoapods

手动

  1. 下载源代码。
  2. 解压缩zip文件,只需将文件夹Classes简单地拖到项目中。
  3. 请确保已勾选 在需要时复制项目

Cocoapods

HJLayout 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中。

pod 'HJWeather'

教程

1. TodayWeather 入门

  • 使用代码入门。提供今天、明天、后天天气数据。
public func getTotalCurrentWeather(lat: String, long: String, completed: @escaping (_ weatherinfo: Dictionary<String,Dictionary<String,String>>) -> Void)

只需使用经纬度调用函数。

var weatherInfo = [String:[String:String]]()
WeatherApiHelper.shared.getTotalCurrentWeather(lat: lat, long: long) { [weak self] (weatherinfo) in
    self?.weatherInfo = weatherinfo
    self?.weatherCollectionView.reloadData()
}
//data example
//"202009021500": ["UUU": "-0.5", "REH": "90", "R06": "5", "api_rain_image": "RAIN_D01", "api_sky_image": "SKY_D04", "T3H": "26", "SKY": "흐림", "POP": "80", "PTY": "비", "TMX": "28.0", "VEC": "18", "WSD": "2.1", "VVV": "-2"]

2. AmPmWeather 入门

  • 使用代码入门。提供今天、明天、后天 Am、Pm 天气数据。
public func getTomorrowWeather(future: Bool, completed: @escaping (_ tomorrowInfo: [futureWeatherModel]) -> Void)

简单调用函数 * future = false 是用于 AmPm Weather,future = true 是用于 Future Weather
请查看实现示例

var ampmWeatherInfo = [futureWeatherModel]()
WeatherApiHelper.shared.getTomorrowWeather(future: future) { [weak self] (weather) in
    self?.ampmWeatherInfo = weather
}

FutureWeatherModel

@objcMembers
public class futureWeatherModel: NSObject {
    public var rain_text = "" // 강수확률
    public var sky_text = "" // 날씨 image text
    public var temp_Max = "" // 최고기온
    public var temp_Min =  "" // 최저기온
    public var sky = "" // 날씨 (한글)
}

3. FutureWeather 入门

  • 使用代码入门。提供从今天起的未来 3 天至 8 天的信息。
public func getForecastWeather(completed: @escaping (_ forecastInfo: [futureWeatherModel]) -> Void)

首先,使用 getTomorrowWeather( ) 从今天获取 3 天数据(今天、明天、后天)。其次,调用 getForecastWeather( ) 获取 8 天数据。

var futureWeatherInfo = [futureWeatherModel]()
WeatherApiHelper.shared.getTomorrowWeather(future: true) { [weak self] (nearWeather) in
    self?.futureWeatherInfo = nearWeather
    WeatherApiHelper.shared.getForecastWeather { [weak self] (futureWeather) in
        self?.futureWeatherInfo += futureWeather
        self?.weatherCollectionView.reloadData()
    }
}

作者

HJKim95, [email protected]

许可证

HJWeather可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。