diff --git a/HPOpenWeather.xcodeproj/project.pbxproj b/HPOpenWeather.xcodeproj/project.pbxproj index 61a6206..b6022fd 100644 --- a/HPOpenWeather.xcodeproj/project.pbxproj +++ b/HPOpenWeather.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 1B1328C85E81910AE08C0670 /* Pods_HPOpenWeather.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 546B25B43D6E5AB205ED1FE1 /* Pods_HPOpenWeather.framework */; }; - 4909D34302201B0D36ED0AA7 /* Pods_OpenWeatherSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ABEF7AAF1618FE04518D6EAD /* Pods_OpenWeatherSwift.framework */; }; AF5ABCFF1E508091008D0857 /* Forecast.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF5ABCFE1E508091008D0857 /* Forecast.swift */; }; AF7B02E01E5074950083F35F /* Weather.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF7B02DF1E5074950083F35F /* Weather.swift */; }; AFCD309D1E4F7B1800545890 /* OpenWeatherSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = AFCD309B1E4F7B1800545890 /* OpenWeatherSwift.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -17,22 +16,16 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 36763E9BA8D1C5B323F5003E /* Pods-OpenWeatherSwift.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OpenWeatherSwift.debug.xcconfig"; path = "Pods/Target Support Files/Pods-OpenWeatherSwift/Pods-OpenWeatherSwift.debug.xcconfig"; sourceTree = ""; }; 546B25B43D6E5AB205ED1FE1 /* Pods_HPOpenWeather.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HPOpenWeather.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 795E58A63F19CC4F29AA7561 /* Pods-HPOpenWeather.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HPOpenWeather.debug.xcconfig"; path = "Pods/Target Support Files/Pods-HPOpenWeather/Pods-HPOpenWeather.debug.xcconfig"; sourceTree = ""; }; - ABEF7AAF1618FE04518D6EAD /* Pods_OpenWeatherSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OpenWeatherSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; AF5ABCFE1E508091008D0857 /* Forecast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Forecast.swift; sourceTree = ""; }; AF7B02DF1E5074950083F35F /* Weather.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weather.swift; sourceTree = ""; }; - AFAB24281E50846700F2D31B /* OpenWeatherSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenWeatherSwiftTests.swift; sourceTree = ""; }; - AFAB242A1E50846700F2D31B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; AFCD30981E4F7B1800545890 /* HPOpenWeather.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HPOpenWeather.framework; sourceTree = BUILT_PRODUCTS_DIR; }; AFCD309B1E4F7B1800545890 /* OpenWeatherSwift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OpenWeatherSwift.h; sourceTree = ""; }; AFCD309C1E4F7B1800545890 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; AFCD30A31E4F7B2B00545890 /* HPOpenWeather.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HPOpenWeather.swift; sourceTree = ""; }; B104D0A99E9F2BAADFCA60C8 /* Pods-HPOpenWeather.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HPOpenWeather.release.xcconfig"; path = "Pods/Target Support Files/Pods-HPOpenWeather/Pods-HPOpenWeather.release.xcconfig"; sourceTree = ""; }; C3DF2C1D2123226F00D8B636 /* HPOpenWeather.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HPOpenWeather.podspec; sourceTree = SOURCE_ROOT; }; - C82EA37D12FF0D9BD33D4A3F /* Pods_OpenWeatherSwiftTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OpenWeatherSwiftTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - EF51520C2CDE45D3E5186CD8 /* Pods-OpenWeatherSwift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OpenWeatherSwift.release.xcconfig"; path = "Pods/Target Support Files/Pods-OpenWeatherSwift/Pods-OpenWeatherSwift.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -40,7 +33,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 4909D34302201B0D36ED0AA7 /* Pods_OpenWeatherSwift.framework in Frameworks */, 1B1328C85E81910AE08C0670 /* Pods_HPOpenWeather.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -51,8 +43,6 @@ 2020E830BEF3625D7EF90628 /* Pods */ = { isa = PBXGroup; children = ( - 36763E9BA8D1C5B323F5003E /* Pods-OpenWeatherSwift.debug.xcconfig */, - EF51520C2CDE45D3E5186CD8 /* Pods-OpenWeatherSwift.release.xcconfig */, 795E58A63F19CC4F29AA7561 /* Pods-HPOpenWeather.debug.xcconfig */, B104D0A99E9F2BAADFCA60C8 /* Pods-HPOpenWeather.release.xcconfig */, ); @@ -62,28 +52,16 @@ 832BC8D608201E720E1FE47A /* Frameworks */ = { isa = PBXGroup; children = ( - ABEF7AAF1618FE04518D6EAD /* Pods_OpenWeatherSwift.framework */, - C82EA37D12FF0D9BD33D4A3F /* Pods_OpenWeatherSwiftTests.framework */, 546B25B43D6E5AB205ED1FE1 /* Pods_HPOpenWeather.framework */, ); name = Frameworks; sourceTree = ""; }; - AFAB24271E50846700F2D31B /* OpenWeatherSwiftTests */ = { - isa = PBXGroup; - children = ( - AFAB24281E50846700F2D31B /* OpenWeatherSwiftTests.swift */, - AFAB242A1E50846700F2D31B /* Info.plist */, - ); - path = OpenWeatherSwiftTests; - sourceTree = ""; - }; AFCD308E1E4F7B1800545890 = { isa = PBXGroup; children = ( C3DF2C1D2123226F00D8B636 /* HPOpenWeather.podspec */, - AFCD309A1E4F7B1800545890 /* OpenWeatherSwift */, - AFAB24271E50846700F2D31B /* OpenWeatherSwiftTests */, + AFCD309A1E4F7B1800545890 /* HPOpenWeather */, AFCD30991E4F7B1800545890 /* Products */, 2020E830BEF3625D7EF90628 /* Pods */, 832BC8D608201E720E1FE47A /* Frameworks */, @@ -98,7 +76,7 @@ name = Products; sourceTree = ""; }; - AFCD309A1E4F7B1800545890 /* OpenWeatherSwift */ = { + AFCD309A1E4F7B1800545890 /* HPOpenWeather */ = { isa = PBXGroup; children = ( AFCD30A31E4F7B2B00545890 /* HPOpenWeather.swift */, @@ -107,7 +85,7 @@ AFCD309B1E4F7B1800545890 /* OpenWeatherSwift.h */, AFCD309C1E4F7B1800545890 /* Info.plist */, ); - path = OpenWeatherSwift; + path = HPOpenWeather; sourceTree = ""; }; /* End PBXGroup section */ @@ -352,11 +330,11 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = OpenWeatherSwift/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/HPOpenWeather/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.henrikpanhans.OpenWeatherSwift; + PRODUCT_BUNDLE_IDENTIFIER = com.henrikpanhans.HPOpenWeather; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -375,11 +353,11 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = OpenWeatherSwift/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/HPOpenWeather/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.henrikpanhans.OpenWeatherSwift; + PRODUCT_BUNDLE_IDENTIFIER = com.henrikpanhans.HPOpenWeather; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_VERSION = 4.2; diff --git a/HPOpenWeather.xcodeproj/xcuserdata/henrikpanhans.xcuserdatad/xcschemes/xcschememanagement.plist b/HPOpenWeather.xcodeproj/xcuserdata/henrikpanhans.xcuserdatad/xcschemes/xcschememanagement.plist index 0f46158..7eaa5c1 100644 --- a/HPOpenWeather.xcodeproj/xcuserdata/henrikpanhans.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/HPOpenWeather.xcodeproj/xcuserdata/henrikpanhans.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ HPOpenWeather.xcscheme_^#shared#^_ orderHint - 0 + 3 OpenWeatherSwift.xcscheme_^#shared#^_ diff --git a/HPOpenWeather.xcworkspace/contents.xcworkspacedata b/HPOpenWeather.xcworkspace/contents.xcworkspacedata index f6f94d8..27ce4a6 100644 --- a/HPOpenWeather.xcworkspace/contents.xcworkspacedata +++ b/HPOpenWeather.xcworkspace/contents.xcworkspacedata @@ -2,12 +2,9 @@ + location = "group:HPOpenWeather.xcodeproj"> - - diff --git a/HPOpenWeather.xcworkspace/xcuserdata/henrikpanhans.xcuserdatad/UserInterfaceState.xcuserstate b/HPOpenWeather.xcworkspace/xcuserdata/henrikpanhans.xcuserdatad/UserInterfaceState.xcuserstate index 99dd540..74bf7fa 100644 Binary files a/HPOpenWeather.xcworkspace/xcuserdata/henrikpanhans.xcuserdatad/UserInterfaceState.xcuserstate and b/HPOpenWeather.xcworkspace/xcuserdata/henrikpanhans.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/HPOpenWeather/Forecast.swift b/HPOpenWeather/Forecast.swift new file mode 100644 index 0000000..38af70c --- /dev/null +++ b/HPOpenWeather/Forecast.swift @@ -0,0 +1,92 @@ +// +// Forecast.swift +// OpenWeatherSwift +// +// Created by Henrik Panhans on 12.02.17. +// Copyright © 2017 Henrik Panhans. All rights reserved. +// + +import SwiftyJSON + +public enum ForecastType: String { + case Hourly = "http://api.openweathermap.org/data/2.5/forecast?"; + case Daily = "http://api.openweathermap.org/data/2.5/forecast/daily?" +} + +public class Forecast { + public var city: String = "" + public var country: String = "" + public var cityID: String = "" + public var tempNight = [Double]() + public var tempMin = [Double]() + public var tempEve = [Double]() + public var tempDay = [Double]() + public var tempMax = [Double]() + public var tempMorn = [Double]() + public var clouds = [Double]() + public var conditions = [String]() + public var pressures = [Double]() + public var humidities = [Double]() + public var rain = [Double]() + public var dates = [Date]() + public var dt = [Double]() + public var icon = [String]() +// public var weatherSmallDesc = [String]() +// public var weatherDesc = [String]() + + public init(data: JSON, type: ForecastType) { + if type == .Hourly { + // self.city = data["city"]["name"].stringValue + // self.country = data["city"]["country"].stringValue + // self.cityID = data["city"]["id"].stringValue + // + // let subdata = data["list"] + // + // for subJSON in subdata.array! { + // self.temperatures.append(subJSON["main"]["temp"].doubleValue) + // self.clouds.append(subJSON["clouds"]["all"].doubleValue) + // self.conditions.append(subJSON["weather"]["main"].stringValue) + // self.pressures.append(subJSON["main"]["pressure"].doubleValue) + // self.humidities.append(subJSON["main"]["humidity"].doubleValue) + // self.rain.append(subJSON["rain"]["3h"].doubleValue) + // self.icon.append(subJSON["weather"][0]["icon"].stringValue) + // self.dt.append(subJSON["dt"].doubleValue) + // + //// let date = subJSON["dt_txt"].stringValue.convertToDate(withFormat: "yyyy-MM-dd HH:mm:ss") + // let date = NSDate(timeIntervalSince1970: subJSON["dt"].doubleValue) + // + // self.dates.append(date as Date) + // } + } else { + self.city = data["city"]["name"].stringValue + self.country = data["city"]["country"].stringValue + self.cityID = data["city"]["id"].stringValue + + let subdata = data["list"] + + for subJson in subdata.array! { + self.tempNight.append(subJson["temp"]["night"].doubleValue) + self.tempMin.append(subJson["temp"]["min"].doubleValue) + self.tempEve.append(subJson["temp"]["eve"].doubleValue) + self.tempDay.append(subJson["temp"]["day"].doubleValue) + self.tempMax.append(subJson["temp"]["max"].doubleValue) + self.tempMorn.append(subJson["temp"]["morn"].doubleValue) + + self.conditions.append(subJson["weather"]["description"].stringValue) + self.clouds.append(subJson["clouds"].doubleValue) + self.pressures.append(subJson["pressure"].doubleValue) + self.humidities.append(subJson["humidity"].doubleValue) + self.icon.append(subJson["weather"][0]["icon"].stringValue) +// self.weatherSmallDesc(subJson["weather"][0]["main"].stringValue) +// self.weatherDesc(subJson["weather"][0]["description"].stringValue) + + + self.dt.append(subJson["dt"].doubleValue) + + let date = NSDate(timeIntervalSince1970: subJson["dt"].doubleValue) + + self.dates.append(date as Date) + } + } + } +} diff --git a/HPOpenWeather/HPOpenWeather.swift b/HPOpenWeather/HPOpenWeather.swift new file mode 100644 index 0000000..9be009b --- /dev/null +++ b/HPOpenWeather/HPOpenWeather.swift @@ -0,0 +1,202 @@ +// +// OpenWeatherApi.swift +// Dunkel Sky Finder +// +// Created by Henrik Panhans on 15/01/2017. +// Copyright © 2017 Henrik Panhans. All rights reserved. +// + +import Alamofire +import CoreLocation +import SwiftyJSON + +public enum TemperatureUnit: String { + case Celsius = "metric" + case Fahrenheit = "imperial" + case Kelvin = "" +} + +public enum Language : String { + case English = "en", + Russian = "ru", + Italian = "it", + Spanish = "es", + Ukrainian = "uk", + German = "de", + Portuguese = "pt", + Romanian = "ro", + Polish = "pl", + Finnish = "fi", + Dutch = "nl", + French = "fr", + Bulgarian = "bg", + Swedish = "sv", + ChineseTraditional = "zh_tw", + ChineseSimplified = "zh_cn", + Turkish = "tr", + Croatian = "hr", + Catalan = "ca" +} + +public class OpenWeatherSwift { + + private let currentBase = "https://api.openweathermap.org/data/2.5/weather?" + + private var params = [String : AnyObject]() + public var temperatureFormat: TemperatureUnit = .Kelvin { + didSet { + params["units"] = temperatureFormat.rawValue as AnyObject? + } + } + + public var language: Language = .English { + didSet { + params["lang"] = language.rawValue as AnyObject? + } + } + + public init(apiKey: String) { + params["appid"] = apiKey as AnyObject? + } + + public convenience init(apiKey: String, temperatureFormat: TemperatureUnit) { + self.init(apiKey: apiKey) + self.temperatureFormat = temperatureFormat + self.params["units"] = temperatureFormat.rawValue as AnyObject? + + } + + public convenience init(apiKey: String, temperatureFormat: TemperatureUnit, lang: Language) { + self.init(apiKey: apiKey, temperatureFormat: temperatureFormat) + + self.language = lang + self.temperatureFormat = temperatureFormat + + params["units"] = temperatureFormat.rawValue as AnyObject? + params["lang"] = lang.rawValue as AnyObject? + } + + + func encode(params: [String: AnyObject]) -> String { + var stringToAppend = String() + + for param in params { + stringToAppend = stringToAppend + "&\(param.key)=\(param.value)" + } + + return stringToAppend + } + + public func getIconFromID(id: String) -> UIImage { + let url = URL(string: "http://openweathermap.org/img/w/\(id).png") + do { + let data = try Data.init(contentsOf: url!) + let image = UIImage(data: data) + + return image! + } catch { + print("error") + } + + return UIImage() + } + + public func currentWeatherByCity(name: String, completionHandler: @escaping (_ result: JSON) -> ()) { + let apiURL = currentBase + "q=\(name)" + encode(params: params) + + Alamofire.request(apiURL).responseJSON { (response) in + if response.result.isSuccess { + let json = JSON(response.result.value as Any) + + completionHandler(json) + } else { + print("error") + } + } + } + + public func currentWeatherByCoordinates(coords: CLLocationCoordinate2D, completionHandler: @escaping (_ result: JSON) -> ()) { + let apiURL = currentBase + "lat=\(coords.latitude)&lon=\(coords.longitude)" + encode(params: params) + + Alamofire.request(apiURL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!).responseJSON { (response) in + if response.result.isSuccess { + let json = JSON(response.result.value as Any) + + completionHandler(json) + } else { + print("error") + } + } + } + + public func currentWeatherByID(id: String, completionHandler: @escaping (_ result: Any) -> ()) { + let apiURL = currentBase + "id=\(id)" + encode(params: params) + + Alamofire.request(apiURL).responseJSON { (response) in + if response.result.isSuccess { + let json = JSON(response.result.value as Any) + + completionHandler(json) + } else { + print("error") + } + } + } + + public func currentWeatherByZIP(code: String, countryCode: String, completionHandler: @escaping (_ result: Any) -> ()) { + let apiURL = currentBase + "zip=\(code),\(countryCode)" + encode(params: params) + + Alamofire.request(apiURL).responseJSON { (response) in + if response.result.isSuccess { + let json = JSON(response.result.value as Any) + + completionHandler(json) + } else { + print("error") + } + } + } + + public func forecastWeatherByCity(name: String, type: ForecastType, completionHandler: @escaping (_ result: JSON) -> ()) { + let apiURL = type.rawValue + "q=\(name)" + encode(params: params) + + Alamofire.request(apiURL).responseJSON { (response) in + if response.result.isSuccess { + let json = JSON(response.result.value as Any) + + completionHandler(json) + } else { + print("error") + } + } + } + + public func forecastWeatherByCoordinates(coords: CLLocationCoordinate2D, type: ForecastType, completionHandler: @escaping (_ result: JSON) -> ()) { + let apiURL = type.rawValue + "lat=\(coords.latitude)&lon=\(coords.longitude)" + encode(params: params) + + Alamofire.request(apiURL).responseJSON { (response) in + if response.result.isSuccess { + let json = JSON(response.result.value as Any) + + completionHandler(json) + } else { + print("error") + } + + } + } + + public func forecastWeatherByID(id: String, type: ForecastType, completionHandler: @escaping (_ result: JSON) -> ()) { + let apiURL = type.rawValue + "id=\(id)" + encode(params: params) + + Alamofire.request(apiURL).responseJSON { (response) in + if response.result.isSuccess { + let json = JSON(response.result.value as Any) + + completionHandler(json) + } else { + print("error") + } + } + } +} diff --git a/OpenWeatherSwiftTests/Info.plist b/HPOpenWeather/Info.plist similarity index 81% rename from OpenWeatherSwiftTests/Info.plist rename to HPOpenWeather/Info.plist index 6c6c23c..d7fb954 100644 --- a/OpenWeatherSwiftTests/Info.plist +++ b/HPOpenWeather/Info.plist @@ -13,10 +13,12 @@ CFBundleName $(PRODUCT_NAME) CFBundlePackageType - BNDL + FMWK CFBundleShortVersionString - 1.0 + 1.2.0 CFBundleVersion - 1 + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + diff --git a/HPOpenWeather/OpenWeatherSwift.h b/HPOpenWeather/OpenWeatherSwift.h new file mode 100644 index 0000000..bfe87d9 --- /dev/null +++ b/HPOpenWeather/OpenWeatherSwift.h @@ -0,0 +1,19 @@ +// +// OpenWeatherSwift.h +// OpenWeatherSwift +// +// Created by Henrik Panhans on 11.02.17. +// Copyright © 2017 Henrik Panhans. All rights reserved. +// + +#import + +//! Project version number for OpenWeatherSwift. +FOUNDATION_EXPORT double OpenWeatherSwiftVersionNumber; + +//! Project version string for OpenWeatherSwift. +FOUNDATION_EXPORT const unsigned char OpenWeatherSwiftVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/HPOpenWeather/Weather.swift b/HPOpenWeather/Weather.swift new file mode 100644 index 0000000..d9af09f --- /dev/null +++ b/HPOpenWeather/Weather.swift @@ -0,0 +1,75 @@ +// +// Weather.swift +// Dunkel Sky Finder +// +// Created by Henrik Panhans on 16/01/2017. +// Copyright © 2017 Henrik Panhans. All rights reserved. +// + +import SwiftyJSON + +public class Weather { + public var humidity: Int + public var id: Int + public var clouds: Float + public var country: String + public var visibility: Int + public var airPressure: Int + + public var temperature: Int + public var low: Int + public var high: Int + public var location: String + public var condition: String + public var icon: String + + + public init(data: JSON) { + self.humidity = data["main"]["humidity"].intValue + self.id = data["id"].intValue + self.clouds = data["clouds"]["all"].floatValue + self.country = data["sys"]["country"].stringValue + self.visibility = data["visibility"].intValue + self.airPressure = data["main"]["pressure"].intValue + self.temperature = data["main"]["temp"].intValue + self.low = data["main"]["temp_min"].intValue + self.high = data["main"]["temp_max"].intValue + self.location = data["name"].stringValue + self.condition = data["weather"][0]["main"].stringValue + self.icon = data["weather"][0]["icon"].stringValue + } +} + +extension Double { + func convertTimeToString() -> String { + let currentDateTime = Date(timeIntervalSince1970: self) + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "dd/MM hh:mm" + return dateFormatter.string(from: currentDateTime) + } +} + +public extension String { + func convertToDate(withFormat: String) -> Date { + TimeZone.ReferenceType.default = TimeZone(abbreviation: "BST")! + + let dateFormatter = DateFormatter() + dateFormatter.timeZone = TimeZone.ReferenceType.default + dateFormatter.dateFormat = withFormat + + return dateFormatter.date(from: self)! + } +} + +public extension Date { + func convertToString() -> String { + TimeZone.ReferenceType.default = TimeZone(abbreviation: "BST")! + + let dateFormatter = DateFormatter() + dateFormatter.timeZone = TimeZone.ReferenceType.default + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + + return dateFormatter.string(from: self) + } +} + diff --git a/OpenWeatherSwiftTests/OpenWeatherSwiftTests.swift b/OpenWeatherSwiftTests/OpenWeatherSwiftTests.swift deleted file mode 100644 index 7da5908..0000000 --- a/OpenWeatherSwiftTests/OpenWeatherSwiftTests.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// OpenWeatherSwiftTests.swift -// OpenWeatherSwiftTests -// -// Created by Henrik Panhans on 12.02.17. -// Copyright © 2017 Henrik Panhans. All rights reserved. -// - -import XCTest -import OpenWeatherSwift - -class OpenWeatherSwiftTests: XCTestCase { - var api: OpenWeatherSwift! - var forecast: Forecast! - - override func setUp() { - super.setUp() - - api = OpenWeatherSwift(apiKey: "47768dd5aac8cb37eaaf9a13c47f156a", temperatureFormat: .Celsius) - - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func test() { - - } -}