diff --git a/APIClient.xcodeproj/project.pbxproj b/APIClient.xcodeproj/project.pbxproj index d57524a..3345914 100644 --- a/APIClient.xcodeproj/project.pbxproj +++ b/APIClient.xcodeproj/project.pbxproj @@ -7,6 +7,15 @@ objects = { /* Begin PBXBuildFile section */ + 321A60FE1D09FD200024A145 /* Weather.swift in Sources */ = {isa = PBXBuildFile; fileRef = 321A60FD1D09FD200024A145 /* Weather.swift */; }; + 32284E5A1D04395C003BC1EF /* WeatherViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32284E591D04395C003BC1EF /* WeatherViewController.swift */; }; + 32284E5C1D0442AF003BC1EF /* GoogleGeocodingAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32284E5B1D0442AF003BC1EF /* GoogleGeocodingAPI.swift */; }; + 32284E601D044FF7003BC1EF /* Forecast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32284E5F1D044FF7003BC1EF /* Forecast.swift */; }; + 324F0F8E1D0AD1FA00F24085 /* WeatherTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324F0F8D1D0AD1FA00F24085 /* WeatherTableViewCell.swift */; }; + 32A28C161D057D9C002D41CA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32A28C151D057D9C002D41CA /* Images.xcassets */; }; + 32A28C181D058880002D41CA /* ForecastAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A28C171D058880002D41CA /* ForecastAPI.swift */; }; + 32A28C1A1D058A69002D41CA /* City.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A28C191D058A69002D41CA /* City.swift */; }; + 32FBADA41D06306600D23B0D /* WeatherListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32FBADA31D06306600D23B0D /* WeatherListViewController.swift */; }; 872A275C1CF0D87100A988C4 /* APIResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 872A275B1CF0D87100A988C4 /* APIResource.swift */; }; 874D06591CEF295E009A494D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 874D06581CEF295E009A494D /* AppDelegate.swift */; }; 874D065E1CEF295E009A494D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 874D065C1CEF295E009A494D /* Main.storyboard */; }; @@ -16,8 +25,17 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 321A60FD1D09FD200024A145 /* Weather.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weather.swift; sourceTree = ""; }; + 32284E591D04395C003BC1EF /* WeatherViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherViewController.swift; sourceTree = ""; }; + 32284E5B1D0442AF003BC1EF /* GoogleGeocodingAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GoogleGeocodingAPI.swift; sourceTree = ""; }; + 32284E5F1D044FF7003BC1EF /* Forecast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Forecast.swift; sourceTree = ""; }; + 324F0F8D1D0AD1FA00F24085 /* WeatherTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherTableViewCell.swift; sourceTree = ""; }; + 32A28C151D057D9C002D41CA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + 32A28C171D058880002D41CA /* ForecastAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForecastAPI.swift; sourceTree = ""; }; + 32A28C191D058A69002D41CA /* City.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = City.swift; sourceTree = ""; }; + 32FBADA31D06306600D23B0D /* WeatherListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherListViewController.swift; sourceTree = ""; }; 872A275B1CF0D87100A988C4 /* APIResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APIResource.swift; sourceTree = ""; }; - 874D06551CEF295E009A494D /* APIClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = APIClient.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 874D06551CEF295E009A494D /* WeatherClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WeatherClient.app; sourceTree = BUILT_PRODUCTS_DIR; }; 874D06581CEF295E009A494D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 874D065D1CEF295E009A494D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 874D065F1CEF295E009A494D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -43,6 +61,9 @@ 872A27571CF0D4E200A988C4 /* View Controller */ = { isa = PBXGroup; children = ( + 32284E591D04395C003BC1EF /* WeatherViewController.swift */, + 32FBADA31D06306600D23B0D /* WeatherListViewController.swift */, + 324F0F8D1D0AD1FA00F24085 /* WeatherTableViewCell.swift */, ); name = "View Controller"; sourceTree = ""; @@ -58,6 +79,11 @@ isa = PBXGroup; children = ( 872A275B1CF0D87100A988C4 /* APIResource.swift */, + 32284E5B1D0442AF003BC1EF /* GoogleGeocodingAPI.swift */, + 32A28C171D058880002D41CA /* ForecastAPI.swift */, + 32284E5F1D044FF7003BC1EF /* Forecast.swift */, + 32A28C191D058A69002D41CA /* City.swift */, + 321A60FD1D09FD200024A145 /* Weather.swift */, ); name = Model; sourceTree = ""; @@ -85,7 +111,7 @@ 874D06561CEF295E009A494D /* Products */ = { isa = PBXGroup; children = ( - 874D06551CEF295E009A494D /* APIClient.app */, + 874D06551CEF295E009A494D /* WeatherClient.app */, ); name = Products; sourceTree = ""; @@ -99,6 +125,7 @@ 872A27581CF0D4EB00A988C4 /* View */, 872A27591CF0D64A00A988C4 /* Model */, 872A275A1CF0D65300A988C4 /* Supporting Files */, + 32A28C151D057D9C002D41CA /* Images.xcassets */, ); path = APIClient; sourceTree = ""; @@ -140,7 +167,7 @@ ); name = APIClient; productName = APIClient; - productReference = 874D06551CEF295E009A494D /* APIClient.app */; + productReference = 874D06551CEF295E009A494D /* WeatherClient.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ @@ -155,6 +182,7 @@ TargetAttributes = { 874D06541CEF295E009A494D = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = LS389VJ9WF; }; }; }; @@ -182,6 +210,7 @@ buildActionMask = 2147483647; files = ( 874D06631CEF295E009A494D /* LaunchScreen.storyboard in Resources */, + 32A28C161D057D9C002D41CA /* Images.xcassets in Resources */, 874D06601CEF295E009A494D /* Assets.xcassets in Resources */, 874D065E1CEF295E009A494D /* Main.storyboard in Resources */, ); @@ -242,8 +271,16 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 324F0F8E1D0AD1FA00F24085 /* WeatherTableViewCell.swift in Sources */, 872A275C1CF0D87100A988C4 /* APIResource.swift in Sources */, + 32A28C181D058880002D41CA /* ForecastAPI.swift in Sources */, + 32284E5C1D0442AF003BC1EF /* GoogleGeocodingAPI.swift in Sources */, + 32284E5A1D04395C003BC1EF /* WeatherViewController.swift in Sources */, + 321A60FE1D09FD200024A145 /* Weather.swift in Sources */, + 32284E601D044FF7003BC1EF /* Forecast.swift in Sources */, + 32FBADA41D06306600D23B0D /* WeatherListViewController.swift in Sources */, 874D06591CEF295E009A494D /* AppDelegate.swift in Sources */, + 32A28C1A1D058A69002D41CA /* City.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -359,10 +396,14 @@ baseConfigurationReference = 93EFAB13AE62F1B6FB2683B2 /* Pods-APIClient.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = APIClient/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClient"; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.coli-n.APIClient"; + PRODUCT_NAME = WeatherClient; + PROVISIONING_PROFILE = ""; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -371,10 +412,15 @@ baseConfigurationReference = FFE13D543A95D28F27CFBDA4 /* Pods-APIClient.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = APIClient/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClient"; + "PRIVATE_HEADERS_FOLDER_PATH[sdk=*]" = "$(CONTENTS_FOLDER_PATH)/PrivateHeaders"; + PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.coli-n.APIClient"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; diff --git a/APIClient/AppDelegate.swift b/APIClient/AppDelegate.swift index 630c3ed..b415afa 100644 --- a/APIClient/AppDelegate.swift +++ b/APIClient/AppDelegate.swift @@ -7,14 +7,33 @@ // import UIKit +import Moya @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? + let googleAPI = MoyaProvider() + let forecastAPI = MoyaProvider() - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(avarication: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + + if let weatherviewcontroller = (window?.rootViewController as? UINavigationController)?.topViewController as? WeatherViewController { + + // Pass the PokeAPI Provider on to the root view controller + weatherviewcontroller.forecastAPI = forecastAPI + weatherviewcontroller.googleAPI = googleAPI + } + + return true + } + + // MARK: State Preservation + func application(application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool { + return true + } + func application(application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool { return true } diff --git a/APIClient/Base.lproj/LaunchScreen.storyboard b/APIClient/Base.lproj/LaunchScreen.storyboard index ebf48f6..f6e2022 100644 --- a/APIClient/Base.lproj/LaunchScreen.storyboard +++ b/APIClient/Base.lproj/LaunchScreen.storyboard @@ -1,5 +1,5 @@ - + diff --git a/APIClient/Base.lproj/Main.storyboard b/APIClient/Base.lproj/Main.storyboard index 69b2fbf..09e2be2 100644 --- a/APIClient/Base.lproj/Main.storyboard +++ b/APIClient/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -8,11 +8,23 @@ - - + + + + + + + + + + + + + + @@ -21,24 +33,254 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/APIClient/City.swift b/APIClient/City.swift new file mode 100644 index 0000000..627cab6 --- /dev/null +++ b/APIClient/City.swift @@ -0,0 +1,51 @@ +// +// City.swift +// APIClient +// +// Created by Colin Otchere on 06.06.16. +// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. +// + +import Foundation +import Moya +import Freddy + +struct CityRawData: JSONDecodable{ + + + let status: String + let result: [CityDetail] + + init(json: JSON) throws { + self.status = try json.string("status") + self.result = try json.arrayOf("results") + } + + struct CityDetail:JSONDecodable { + let formatedAdress: String + let geometry: Geometry + init(json: JSON) throws { + self.formatedAdress = try json.string("formatted_address") + self.geometry = try json.decode("geometry") + } + } +} + +struct Geometry: JSONDecodable{ + + let location: Coordination + init(json: JSON) throws { + self.location = try json.decode("location") + } +} + +struct Coordination: JSONDecodable{ + + let lat: Double + let lng: Double + + init(json: JSON) throws { + self.lat = try json.double("lat") + self.lng = try json.double("lng") + } +} \ No newline at end of file diff --git a/APIClient/Forecast.swift b/APIClient/Forecast.swift new file mode 100644 index 0000000..93bdf27 --- /dev/null +++ b/APIClient/Forecast.swift @@ -0,0 +1,193 @@ +// +// Weather.swift +// APIClient +// +// Created by Colin Otchere on 05.06.16. +// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. +// + +import Foundation +import Freddy +import UIKit + +struct WeatherRawData:JSONDecodable{ + + let currentWeather: Weather + let dailyWeather: Data + let timezone: String + + init(json: JSON) throws { + self.timezone = try json.string("timezone") + self.currentWeather = try json.decode("currently") + self.dailyWeather = try json.decode("daily") + } +} + +struct Data: JSONDecodable{ + + let data: [WeatherData] + + init(json: JSON) throws { + self.data = try json.arrayOf("data") + } +} +struct Weather:JSONDecodable{ + + let time: Int + let summary: String + let icon: String + var temperatur: Double + var summaryGer: String + + init(json: JSON) throws { + + self.summary = try json.string("summary") + self.time = try json.int("time") + self.icon = try json.string("icon") + self.temperatur = try json.double("temperature") + self.summaryGer = "" + convertToCelsius() + self.summaryGer = translate(self.icon) + } + + mutating func convertToCelsius(){ + self.temperatur = (self.temperatur - 32)*5/9 + } + + mutating func translate(weathertext: String) -> String{ + switch weathertext { + case "clear-day": + return "Heiter" + case "clear-night": + return "klare Nacht" + case "rain": + return "Regen" + case "snow": + return "Schnee" + case "sleet": + return "Schneeregen" + case "wind": + return "windig" + case "fog": + return "neblig" + case "cloudy": + return "bewölckt" + case "partly-cloudy-day": + return "" + case "partly-cloudy-night": + return "leicht bewölkt" + case "hail": + return "Hagel" + case "thunderstorm": + return "Gewitter" + case "tornado": + return "Tornado" + default: + return "keine Wetterdaten" + + } + } +} + +struct WeatherData: JSONDecodable{ + + var time: Double + var date:String + let icon: String + var sunriseTime: Double + var sunsetTime: Double + var minTemp: Double + var maxTemp: Double + var summaryGer: String + + var sunrise: String + var sunset: String + + init(json: JSON) throws { + self.time = try json.double("time") + self.icon = try json.string("icon") + self.sunriseTime = try json.double("sunriseTime") + self.sunsetTime = try json.double("sunsetTime") + self.minTemp = try json.double("temperatureMin") + self.maxTemp = try json.double("temperatureMax") + self.summaryGer = "av" + self.date = "" + self.sunrise="" + self.sunset="" + + self.minTemp = convertToCelsius(self.minTemp) + self.maxTemp = convertToCelsius(self.maxTemp) + + self.sunrise = convertUnixTimeToDate(self.sunriseTime) + self.sunset = convertUnixTimeToDate(self.sunsetTime) + + self.date = dayStringFromTime(self.time) + self.summaryGer = translateToGer(self.icon) + } + + mutating func convertToCelsius(temperatur: Double) -> Double{ + let tmpT = (temperatur - 32)*5/9 + return tmpT + } + + mutating func convertUnixTimeToDate(time: Double) -> String{ + + let dateFormatter = NSDateFormatter() + + dateFormatter.dateFormat = "hh:mm" + dateFormatter.timeStyle = NSDateFormatterStyle.ShortStyle + dateFormatter.timeZone = NSTimeZone.localTimeZone() + + let date = NSDate(timeIntervalSince1970: time) + + return dateFormatter.stringFromDate(date) + } + + mutating func dayStringFromTime(unixTime: Double) -> String { + + let dateFormatter = NSDateFormatter() + + let date = NSDate(timeIntervalSince1970: unixTime) + + dateFormatter.locale = NSLocale(localeIdentifier: NSLocale.currentLocale().localeIdentifier) + dateFormatter.dateFormat = "EEEE" + return dateFormatter.stringFromDate(date) + } + + mutating func translateToGer(weathertext: String) ->String{ + switch weathertext { + case "clear-day": + return "Heiter" + case "clear-night": + return "klare Nacht" + case "rain": + return "Regen" + case "snow": + return "Schnee" + case "sleet": + return "Schneeregen" + case "wind": + return "windig" + case "fog": + return"neblig" + case "cloudy": + return "bewölckt" + case "partly-cloudy-day": + return "leicht bewölkt" + case "partly-cloudy-night": + return "leicht bewölkt" + case "hail": + return "Hagel" + case "thunderstorm": + return "Gewitter" + case "tornado": + return "Tornado" + default: + return "keine Wetterdaten" + + } + } +} + + + diff --git a/APIClient/ForecastAPI.swift b/APIClient/ForecastAPI.swift new file mode 100644 index 0000000..2fcb852 --- /dev/null +++ b/APIClient/ForecastAPI.swift @@ -0,0 +1,69 @@ +// +// ForecastAPI.swift +// APIClient +// +// Created by Colin Otchere on 06.06.16. +// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. +// + +import Foundation +import Moya +import Freddy + +enum ForecastAPI: Moya.TargetType,Cacheable{ + + // MARK: Network Abstraction status + + case cityWeather(coordinate: Coordinate) + + var baseURL: NSURL { return NSURL(string: "https://api.forecast.io")! } + + var path: String { + switch self { + case .cityWeather(coordinate: let coordinate): + print("https://api.forecast.io/forecast/9aa042dabcaa8424727f3a49b9cff386/\(coordinate.commaSeparatedDescription)") + return "/forecast/9aa042dabcaa8424727f3a49b9cff386/\(coordinate.commaSeparatedDescription)" + } + } + + var method: Moya.Method { return .GET } + + var parameters: [String : AnyObject]? { + switch self { + default: return nil + } + } + + // TODO: Provide sample data for testing + var sampleData: NSData { + switch self { + default: return "".dataUsingEncoding(NSUTF8StringEncoding)! + } + } + + var cacheIdentifier: String { + return self.path + } +} + +/// Represents a resource provided by the ForecastAPI by its name +struct Coordinate: Freddy.JSONDecodable { + + let latRes: Double + let lngRes: Double + + init(lat: Double,lng: Double) { + self.latRes = lat + self.lngRes = lng + } + + var commaSeparatedDescription: String { + return String(self.latRes) + "," + String(self.lngRes) + } + + init(json: JSON) throws { + self.latRes = try json.double("latitude") + self.lngRes = try json.double("longitude") + } + +} diff --git a/APIClient/GoogleGeocodingAPI.swift b/APIClient/GoogleGeocodingAPI.swift new file mode 100644 index 0000000..fb21395 --- /dev/null +++ b/APIClient/GoogleGeocodingAPI.swift @@ -0,0 +1,68 @@ +// +// WeatherApi.swift +// APIClient +// +// Created by Colin Otchere on 05.06.16. +// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. +// + +import Foundation +import Moya +import Freddy + +enum GoogleGeocodingAPI: Moya.TargetType,Cacheable{ + + // MARK: Network Abstraction status + + case cityRawData(CityResource) + + var baseURL: NSURL { return NSURL(string: "https://maps.googleapis.com/maps/api")! } + + var path: String { + switch self { + case .cityRawData: return "/geocode/json" + } + } + + var method: Moya.Method { return .GET } + + var parameters: [String : AnyObject]? { + switch self { + case .cityRawData(let namedResource): + return [ + "address": namedResource.name, + "components": "country:DE", + //"key": "AIzaSyBWzX1_Pzrxyf04oADXfHxqHIEkvAHdTAo", + ] + } + } + + // TODO: Provide sample data for testing + var sampleData: NSData { + switch self { + default: return "".dataUsingEncoding(NSUTF8StringEncoding)! + } + } + + var cacheIdentifier: String { + return self.path + } +} + +/// Represents a resource provided by the GoogleGeocodingAPI by its name +struct CityResource: Freddy.JSONDecodable { + + let name: String + + init(name: String) { + self.name = name + } + + init(json: JSON) throws { + self.name = try json.string("") + } + +} + + + diff --git a/APIClient/Images.xcassets/Contents.json b/APIClient/Images.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/APIClient/Images.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/Sunrise-50.imageset/Contents.json b/APIClient/Images.xcassets/Sunrise-50.imageset/Contents.json new file mode 100644 index 0000000..9871e2c --- /dev/null +++ b/APIClient/Images.xcassets/Sunrise-50.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "Sunrise-50.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/Sunrise-50.imageset/Sunrise-50.png b/APIClient/Images.xcassets/Sunrise-50.imageset/Sunrise-50.png new file mode 100644 index 0000000..b2cac55 Binary files /dev/null and b/APIClient/Images.xcassets/Sunrise-50.imageset/Sunrise-50.png differ diff --git a/APIClient/Images.xcassets/Sunset-50.imageset/Contents.json b/APIClient/Images.xcassets/Sunset-50.imageset/Contents.json new file mode 100644 index 0000000..5b8ee6d --- /dev/null +++ b/APIClient/Images.xcassets/Sunset-50.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "Sunset-50.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/Sunset-50.imageset/Sunset-50.png b/APIClient/Images.xcassets/Sunset-50.imageset/Sunset-50.png new file mode 100644 index 0000000..4dc52c7 Binary files /dev/null and b/APIClient/Images.xcassets/Sunset-50.imageset/Sunset-50.png differ diff --git a/APIClient/Images.xcassets/clear-day.imageset/Contents.json b/APIClient/Images.xcassets/clear-day.imageset/Contents.json new file mode 100644 index 0000000..284c522 --- /dev/null +++ b/APIClient/Images.xcassets/clear-day.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "weather-3.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/clear-day.imageset/weather-3.png b/APIClient/Images.xcassets/clear-day.imageset/weather-3.png new file mode 100644 index 0000000..e7139c5 Binary files /dev/null and b/APIClient/Images.xcassets/clear-day.imageset/weather-3.png differ diff --git a/APIClient/Images.xcassets/cloud.imageset/Contents.json b/APIClient/Images.xcassets/cloud.imageset/Contents.json new file mode 100644 index 0000000..34b6090 --- /dev/null +++ b/APIClient/Images.xcassets/cloud.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "sky-2.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/cloud.imageset/sky-2.png b/APIClient/Images.xcassets/cloud.imageset/sky-2.png new file mode 100644 index 0000000..bf2fd21 Binary files /dev/null and b/APIClient/Images.xcassets/cloud.imageset/sky-2.png differ diff --git a/APIClient/Images.xcassets/fog.imageset/Contents.json b/APIClient/Images.xcassets/fog.imageset/Contents.json new file mode 100644 index 0000000..c528f85 --- /dev/null +++ b/APIClient/Images.xcassets/fog.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "weather-2.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/fog.imageset/weather-2.png b/APIClient/Images.xcassets/fog.imageset/weather-2.png new file mode 100644 index 0000000..dad3a49 Binary files /dev/null and b/APIClient/Images.xcassets/fog.imageset/weather-2.png differ diff --git a/APIClient/Images.xcassets/hail.imageset/Contents.json b/APIClient/Images.xcassets/hail.imageset/Contents.json new file mode 100644 index 0000000..e7c9ad4 --- /dev/null +++ b/APIClient/Images.xcassets/hail.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "sky-3.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/hail.imageset/sky-3.png b/APIClient/Images.xcassets/hail.imageset/sky-3.png new file mode 100644 index 0000000..9d2786d Binary files /dev/null and b/APIClient/Images.xcassets/hail.imageset/sky-3.png differ diff --git a/APIClient/Images.xcassets/partly-cloudy-day.imageset/Contents.json b/APIClient/Images.xcassets/partly-cloudy-day.imageset/Contents.json new file mode 100644 index 0000000..a4b1ffe --- /dev/null +++ b/APIClient/Images.xcassets/partly-cloudy-day.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "sky-4.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/partly-cloudy-day.imageset/sky-4.png b/APIClient/Images.xcassets/partly-cloudy-day.imageset/sky-4.png new file mode 100644 index 0000000..af2e439 Binary files /dev/null and b/APIClient/Images.xcassets/partly-cloudy-day.imageset/sky-4.png differ diff --git a/APIClient/Images.xcassets/partly-cloudy-night.imageset/Contents.json b/APIClient/Images.xcassets/partly-cloudy-night.imageset/Contents.json new file mode 100644 index 0000000..3868788 --- /dev/null +++ b/APIClient/Images.xcassets/partly-cloudy-night.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "cloud.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/partly-cloudy-night.imageset/cloud.png b/APIClient/Images.xcassets/partly-cloudy-night.imageset/cloud.png new file mode 100644 index 0000000..a1106aa Binary files /dev/null and b/APIClient/Images.xcassets/partly-cloudy-night.imageset/cloud.png differ diff --git a/APIClient/Images.xcassets/rain.imageset/Contents.json b/APIClient/Images.xcassets/rain.imageset/Contents.json new file mode 100644 index 0000000..5ced6cb --- /dev/null +++ b/APIClient/Images.xcassets/rain.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "sky.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/rain.imageset/sky.png b/APIClient/Images.xcassets/rain.imageset/sky.png new file mode 100644 index 0000000..f4d91ca Binary files /dev/null and b/APIClient/Images.xcassets/rain.imageset/sky.png differ diff --git a/APIClient/Images.xcassets/sleet.imageset/Contents.json b/APIClient/Images.xcassets/sleet.imageset/Contents.json new file mode 100644 index 0000000..491ccd8 --- /dev/null +++ b/APIClient/Images.xcassets/sleet.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "sky-5.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/sleet.imageset/sky-5.png b/APIClient/Images.xcassets/sleet.imageset/sky-5.png new file mode 100644 index 0000000..375264d Binary files /dev/null and b/APIClient/Images.xcassets/sleet.imageset/sky-5.png differ diff --git a/APIClient/Images.xcassets/snow.imageset/Contents.json b/APIClient/Images.xcassets/snow.imageset/Contents.json new file mode 100644 index 0000000..78913dd --- /dev/null +++ b/APIClient/Images.xcassets/snow.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "weather-1.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/snow.imageset/weather-1.png b/APIClient/Images.xcassets/snow.imageset/weather-1.png new file mode 100644 index 0000000..1e423f3 Binary files /dev/null and b/APIClient/Images.xcassets/snow.imageset/weather-1.png differ diff --git a/APIClient/Images.xcassets/thunderstorm.imageset/Contents.json b/APIClient/Images.xcassets/thunderstorm.imageset/Contents.json new file mode 100644 index 0000000..4d25238 --- /dev/null +++ b/APIClient/Images.xcassets/thunderstorm.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "weather.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/thunderstorm.imageset/weather.png b/APIClient/Images.xcassets/thunderstorm.imageset/weather.png new file mode 100644 index 0000000..0934201 Binary files /dev/null and b/APIClient/Images.xcassets/thunderstorm.imageset/weather.png differ diff --git a/APIClient/Images.xcassets/wind.imageset/Contents.json b/APIClient/Images.xcassets/wind.imageset/Contents.json new file mode 100644 index 0000000..9370c42 --- /dev/null +++ b/APIClient/Images.xcassets/wind.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "sky-1.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/APIClient/Images.xcassets/wind.imageset/sky-1.png b/APIClient/Images.xcassets/wind.imageset/sky-1.png new file mode 100644 index 0000000..a2402ef Binary files /dev/null and b/APIClient/Images.xcassets/wind.imageset/sky-1.png differ diff --git a/APIClient/Info.plist b/APIClient/Info.plist index 40c6215..4f663c8 100644 --- a/APIClient/Info.plist +++ b/APIClient/Info.plist @@ -30,11 +30,11 @@ armv7 + UIStatusBarStyle + UIStatusBarStyleLightContent UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad diff --git a/APIClient/Weather.swift b/APIClient/Weather.swift new file mode 100644 index 0000000..300694c --- /dev/null +++ b/APIClient/Weather.swift @@ -0,0 +1,29 @@ +// +// Weather.swift +// APIClient +// +// Created by Colin Otchere on 09.06.16. +// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. +// + +import UIKit + +struct WeatherList { + + let day: String + let sunset: String + let sunrise: String + let maxTemp: String + let minTemp: String + let imageName: String + + init?(day: String,maxTemp: String, minTemp: String, sunrise: String, sunset: String, image: String){ + self.day = day + self.maxTemp = maxTemp + self.minTemp = minTemp + self.sunrise = sunrise + self.sunset = sunset + self.imageName = image + } + +} \ No newline at end of file diff --git a/APIClient/WeatherListViewController.swift b/APIClient/WeatherListViewController.swift new file mode 100644 index 0000000..95cb2c7 --- /dev/null +++ b/APIClient/WeatherListViewController.swift @@ -0,0 +1,48 @@ +// +// WeatherListViewController.swift +// APIClient +// +// Created by Colin Otchere on 07.06.16. +// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. +// + +import Foundation +import UIKit + +class WeatherListViewController: UITableViewController{ + + var weather: [WeatherList]? + var cityname: String = "" + + override func viewDidLoad() { + super.viewDidLoad() + + self.title = cityname + " Forecast" + + } + + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + return 1 + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return (weather?.count)! + } + + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + let cellIdentifier = "WeatherCell" + let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! WeatherTableViewCell + + cell.maxTemp.text = weather![indexPath.row].maxTemp + "°C" + cell.minTemp.text = weather![indexPath.row].minTemp + "°C" + cell.sunrise.text = weather![indexPath.row].sunrise + cell.sunset.text = weather![indexPath.row].sunset + cell.dayLabel.text = weather![indexPath.row].day + cell.weatherImage.image = (image: UIImage(named: weather![indexPath.row].imageName)) + + cell.weatherImage.image = cell.weatherImage.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + cell.weatherImage.tintColor = UIColor.whiteColor() + + return cell + } +} \ No newline at end of file diff --git a/APIClient/WeatherTableViewCell.swift b/APIClient/WeatherTableViewCell.swift new file mode 100644 index 0000000..4fa60c2 --- /dev/null +++ b/APIClient/WeatherTableViewCell.swift @@ -0,0 +1,29 @@ +// +// WeatherTableViewCell.swift +// APIClient +// +// Created by Colin Otchere on 10.06.16. +// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. +// +import UIKit +import Foundation + +class WeatherTableViewCell: UITableViewCell{ + + @IBOutlet weak var dayLabel: UILabel! + @IBOutlet weak var weatherImage: UIImageView! + @IBOutlet weak var sunset: UILabel! + @IBOutlet weak var sunrise: UILabel! + @IBOutlet weak var minTemp: UILabel! + @IBOutlet weak var maxTemp: UILabel! + + + override func awakeFromNib() { + super.awakeFromNib() + } + + override func setSelected(selected: Bool, animated: Bool) { + super.setSelected(selected, animated: true) + } +} + diff --git a/APIClient/WeatherViewController.swift b/APIClient/WeatherViewController.swift new file mode 100644 index 0000000..459a10e --- /dev/null +++ b/APIClient/WeatherViewController.swift @@ -0,0 +1,262 @@ +// +// WeatherViewController.swift +// APIClient +// +// Created by Colin Otchere on 05.06.16. +// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. +// + +import UIKit +import Moya +import Freddy +import AlamofireImage + +class WeatherViewController: UIViewController,UITextFieldDelegate { + + + var forecastAPI: MoyaProvider! + var googleAPI: MoyaProvider! + + var allWeatherData = [WeatherList]() + + var weatherObj: WeatherRawData? { + didSet { + // Configure view + self.timezone.text = weatherObj?.timezone + self.currentWeatherData.text = weatherObj?.dailyWeather.data.first?.summaryGer + self.temperature.text = String(format:"%.1f",(weatherObj?.currentWeather.temperatur)!)+"°C" + self.sunset.text = weatherObj?.dailyWeather.data.first?.sunset + self.sunrise.text = weatherObj?.dailyWeather.data.first?.sunrise + loadImage((weatherObj?.currentWeather.icon)!) + print((weatherObj?.dailyWeather.data.count)) + loadForecast(weatherObj!) + + } + } + + var cityObj: CityRawData? { + didSet{ + self.status.text = cityObj?.status + + self.loadWeatherRawData(Coordinate(lat: (cityObj?.result.first?.geometry.location.lat)!, + lng: (cityObj?.result.first?.geometry.location.lng)!)) + + self.city.text = cityObj?.result.first?.formatedAdress + + } + } + + @IBOutlet weak var weatherIcon: UIImageView! + + @IBOutlet weak var weatherIconIndicator: UIActivityIndicatorView! + @IBOutlet weak var loadingIndicator: UIActivityIndicatorView! + + @IBOutlet weak var cityname: UITextField! + + @IBOutlet weak var forecastButton: UIBarButtonItem! + + @IBOutlet weak var city: UILabel! + @IBOutlet weak var timezone: UILabel! + @IBOutlet weak var sunrise: UILabel! + @IBOutlet weak var sunset: UILabel! + @IBOutlet weak var currentWeatherData: UILabel! + @IBOutlet weak var currentWetter: UILabel! + @IBOutlet weak var temperature: UILabel! + @IBOutlet weak var status: UILabel! + + + override func viewDidLoad() { + super.viewDidLoad() + cityname.delegate = self + + self.loadCityRawData(CityResource(name: "Heidelberg")) + + } + + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + switch segue.identifier! { + case "ForecastView": + guard let weatherListViewController = (segue.destinationViewController as? UINavigationController)?.topViewController as? WeatherListViewController else {break} + + weatherListViewController.weather = allWeatherData + + if let dotRange = city.text!.rangeOfString(",") { + city.text!.removeRange(dotRange.startIndex.. Bool { + textField.resignFirstResponder() + guard let name = cityname.text else { + return true + } + // loadWeatherRawData(NamedResource(name: name)) + self.loadCityRawData(CityResource(name: name)) + return true + } + + func loadCityRawData(name: CityResource){ + loadingIndicator.startAnimating() + weatherIconIndicator.startAnimating() + googleAPI.request(.cityRawData(name)){ result in + self.loadingIndicator.stopAnimating() + self.weatherIconIndicator.stopAnimating() + switch result{ + case .Success(let responseData): + do{ + try responseData.filterSuccessfulStatusCodes() + // Try to parse the response to JSON + let json = try JSON(data: responseData.data) + // Try to decode the JSON to the required type + let cityRawdata = try CityRawData(json: json) + // Configure view according to model + self.cityObj = cityRawdata + } catch { + print(error) + self.status.text = "status: Fehler" + } + case .Failure(let error): + print(error) + } + } + } + + func loadWeatherRawData(coordinate: Coordinate) { + loadingIndicator.startAnimating() + weatherIconIndicator.startAnimating() + self.status.text = "status: lade..." + forecastAPI.request(.cityWeather(coordinate: coordinate)) { result in + self.loadingIndicator.stopAnimating() + self.weatherIconIndicator.stopAnimating() + switch result { + case .Success(let response): + do { + try response.filterSuccessfulStatusCodes() + // Try to parse the response to JSON + let json = try JSON(data: response.data) + // Try to decode the JSON to the required type + let weatherData = try WeatherRawData(json: json) + // Configure view according to model + self.weatherObj = weatherData + + self.status.text = "status: OK" + + } catch { + print(error) + self.status.text = "status: Fehler" + } + case .Failure(let error): + print(error) + } + } + } + + func loadImage(id: String) { + + switch id { + case "clear-day": + self.weatherIcon.image = (image: UIImage(named: "clear-day")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "clear-night": + self.weatherIcon.image = (image: UIImage(named: "partly-cloudy-night")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "rain": + self.weatherIcon.image = (image: UIImage(named: "rain")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "snow": + self.weatherIcon.image = (image: UIImage(named: "snow")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "sleet": + self.weatherIcon.image = (image: UIImage(named: "sleet")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "wind": + self.weatherIcon.image = (image: UIImage(named: "wind")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "fog": + self.weatherIcon.image = (image: UIImage(named: "fog")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "cloudy": + self.weatherIcon.image = (image: UIImage(named: "cloudy")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "partly-cloudy-day": + self.weatherIcon.image = (image: UIImage(named: "partly-cloudy-day")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "partly-cloudy-night": + self.weatherIcon.image = (image: UIImage(named: "partly-cloudy-night")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "hail": + self.weatherIcon.image = (image: UIImage(named: "hail")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "thunderstorm": + self.weatherIcon.image = (image: UIImage(named: "thunderstorm")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + case "tornado": + self.weatherIcon.image = (image: UIImage(named: "wind")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + default: + self.weatherIcon.image = (image: UIImage(named: "sun")) + self.weatherIcon.image = self.weatherIcon.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) + self.weatherIcon.tintColor = UIColor.whiteColor() + } + } + + func loadForecast(obj: WeatherRawData){ + + let days: Int + days = obj.dailyWeather.data.count-1 + + if !allWeatherData.isEmpty + { + allWeatherData = [] + } + + if days > 0{ + + for index in 1...days { + + let obj = WeatherList(day: obj.dailyWeather.data[index].date, + maxTemp: String(format: "%.1f", obj.dailyWeather.data[index].maxTemp), + minTemp: String(format: "%.1f", obj.dailyWeather.data[index].minTemp), + sunrise: obj.dailyWeather.data[index].sunrise, + sunset: obj.dailyWeather.data[index].sunset, + image: obj.dailyWeather.data[index].icon) + allWeatherData.append(obj!) + } + } + else { + self.forecastButton.enabled = false + } + } +} \ No newline at end of file diff --git a/Podfile b/Podfile index 9f9e096..7ddfd75 100644 --- a/Podfile +++ b/Podfile @@ -6,4 +6,4 @@ pod 'Freddy' pod 'AlamofireImage' pod 'AwesomeCache' -target 'APIClient' +target 'WeatherClient'