diff --git a/.DS_Store b/.DS_Store index f08222d..ad510d6 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/WeatherApp/.DS_Store b/WeatherApp/.DS_Store index d26d934..9c64707 100644 Binary files a/WeatherApp/.DS_Store and b/WeatherApp/.DS_Store differ diff --git a/WeatherApp/WeatherApp.xcodeproj/project.pbxproj b/WeatherApp/WeatherApp.xcodeproj/project.pbxproj index cd17f80..85b767b 100644 --- a/WeatherApp/WeatherApp.xcodeproj/project.pbxproj +++ b/WeatherApp/WeatherApp.xcodeproj/project.pbxproj @@ -9,11 +9,13 @@ /* Begin PBXBuildFile section */ 0802D1FF1DE9DCAF00054425 /* DayForecastViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0802D1FE1DE9DCAF00054425 /* DayForecastViewController.swift */; }; 0802D2021DE9DEE700054425 /* WeatherState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0802D2011DE9DEE700054425 /* WeatherState.swift */; }; - 4D5C914D1E2CE3CD005D947F /* add_2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D5C914C1E2CE3CD005D947F /* add_2x.png */; }; 6D1F340E1DF84D0600714FD6 /* TodayViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D1F340D1DF84D0600714FD6 /* TodayViewCell.swift */; }; 843CFBA81E1FFFEF008463E6 /* menu.png in Resources */ = {isa = PBXBuildFile; fileRef = 843CFBA71E1FFFEF008463E6 /* menu.png */; }; 843CFBAA1E200469008463E6 /* CityPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 843CFBA91E200469008463E6 /* CityPickerViewController.swift */; }; 84E7C9A81E2970790027489E /* OpenWeatherMapService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E7C9A71E2970790027489E /* OpenWeatherMapService.swift */; }; + 99A78A001E3001690037292D /* WeatherService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99A789FF1E3001690037292D /* WeatherService.swift */; }; + 99A78A021E3002590037292D /* add_2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 99A78A011E3002590037292D /* add_2x.png */; }; + 99A78A041E3005F30037292D /* WeatherSourceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99A78A031E3005F30037292D /* WeatherSourceViewController.swift */; }; 9D42497B1DBB8E0A00125040 /* ForecastMO+ForecastObjectProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D42497A1DBB8E0A00125040 /* ForecastMO+ForecastObjectProtocol.swift */; }; 9D6A14541DBA83EA00715576 /* CoreDataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D6A14531DBA83EA00715576 /* CoreDataProtocol.swift */; }; 9D6A14561DBA85AD00715576 /* ProviderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D6A14551DBA85AD00715576 /* ProviderProtocol.swift */; }; @@ -47,11 +49,13 @@ /* Begin PBXFileReference section */ 0802D1FE1DE9DCAF00054425 /* DayForecastViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DayForecastViewController.swift; sourceTree = ""; }; 0802D2011DE9DEE700054425 /* WeatherState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherState.swift; sourceTree = ""; }; - 4D5C914C1E2CE3CD005D947F /* add_2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = add_2x.png; path = ../../../../../Downloads/ic_add_black_24dp/ios/ic_add.imageset/add_2x.png; sourceTree = ""; }; 6D1F340D1DF84D0600714FD6 /* TodayViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TodayViewCell.swift; sourceTree = ""; }; 843CFBA71E1FFFEF008463E6 /* menu.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = menu.png; sourceTree = ""; }; 843CFBA91E200469008463E6 /* CityPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CityPickerViewController.swift; sourceTree = ""; }; 84E7C9A71E2970790027489E /* OpenWeatherMapService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenWeatherMapService.swift; sourceTree = ""; }; + 99A789FF1E3001690037292D /* WeatherService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WeatherService.swift; path = ../../../../../Projects/WeatherApp/WeatherApp/WeatherApp/Model/Helpers/WeatherService.swift; sourceTree = ""; }; + 99A78A011E3002590037292D /* add_2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = add_2x.png; path = ../../../../Downloads/add_2x.png; sourceTree = ""; }; + 99A78A031E3005F30037292D /* WeatherSourceViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherSourceViewController.swift; sourceTree = ""; }; 9D42497A1DBB8E0A00125040 /* ForecastMO+ForecastObjectProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "ForecastMO+ForecastObjectProtocol.swift"; path = "../../../Providers/ForecastMO+ForecastObjectProtocol.swift"; sourceTree = ""; }; 9D6A14531DBA83EA00715576 /* CoreDataProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataProtocol.swift; sourceTree = ""; }; 9D6A14551DBA85AD00715576 /* ProviderProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProviderProtocol.swift; sourceTree = ""; }; @@ -105,8 +109,8 @@ 843CFBA61E1FFFD8008463E6 /* Images */ = { isa = PBXGroup; children = ( + 99A78A011E3002590037292D /* add_2x.png */, 843CFBA71E1FFFEF008463E6 /* menu.png */, - 4D5C914C1E2CE3CD005D947F /* add_2x.png */, ); name = Images; sourceTree = ""; @@ -181,6 +185,7 @@ 0802D1FE1DE9DCAF00054425 /* DayForecastViewController.swift */, 843CFBA91E200469008463E6 /* CityPickerViewController.swift */, 6D1F340D1DF84D0600714FD6 /* TodayViewCell.swift */, + 99A78A031E3005F30037292D /* WeatherSourceViewController.swift */, ); path = Controller; sourceTree = ""; @@ -247,6 +252,7 @@ 9DCF9BB31DBA4286007518CC /* Helpers */ = { isa = PBXGroup; children = ( + 99A789FF1E3001690037292D /* WeatherService.swift */, 9DCF9BB41DBA4286007518CC /* Units.swift */, ); name = Helpers; @@ -336,9 +342,9 @@ 9D859B1D1D9E32A80055F23A /* Info.plist in Resources */, 843CFBA81E1FFFEF008463E6 /* menu.png in Resources */, 9D859B1F1D9E32DB0055F23A /* LaunchScreen.storyboard in Resources */, - 4D5C914D1E2CE3CD005D947F /* add_2x.png in Resources */, 9D859B1C1D9E32A80055F23A /* Assets.xcassets in Resources */, 9D859B211D9E335D0055F23A /* Main.storyboard in Resources */, + 99A78A021E3002590037292D /* add_2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -362,8 +368,10 @@ 9DBD3EDD1DBA939C00ED8FEA /* ParserProtocol.swift in Sources */, 9DCF9BC51DBA4286007518CC /* WeatherServiceProtocol.swift in Sources */, 9D42497B1DBB8E0A00125040 /* ForecastMO+ForecastObjectProtocol.swift in Sources */, + 99A78A001E3001690037292D /* WeatherService.swift in Sources */, 9DCF9BC21DBA4286007518CC /* WeatherModel.xcdatamodeld in Sources */, AEC316EB1DE969B8006F9EE8 /* CustomLocationManager.swift in Sources */, + 99A78A041E3005F30037292D /* WeatherSourceViewController.swift in Sources */, 9D859B1B1D9E32A80055F23A /* AppDelegate.swift in Sources */, 0802D1FF1DE9DCAF00054425 /* DayForecastViewController.swift in Sources */, 9D859B051D9E31D30055F23A /* ForecastViewController.swift in Sources */, diff --git a/WeatherApp/WeatherApp.xcodeproj/project.xcworkspace/xcuserdata/orlovvladimir.xcuserdatad/UserInterfaceState.xcuserstate b/WeatherApp/WeatherApp.xcodeproj/project.xcworkspace/xcuserdata/orlovvladimir.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..620b8f9 Binary files /dev/null and b/WeatherApp/WeatherApp.xcodeproj/project.xcworkspace/xcuserdata/orlovvladimir.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/WeatherApp/WeatherApp.xcodeproj/xcuserdata/orlovvladimir.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/WeatherApp/WeatherApp.xcodeproj/xcuserdata/orlovvladimir.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..ad900cf --- /dev/null +++ b/WeatherApp/WeatherApp.xcodeproj/xcuserdata/orlovvladimir.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/WeatherApp/WeatherApp.xcodeproj/xcuserdata/orlovvladimir.xcuserdatad/xcschemes/WeatherApp.xcscheme b/WeatherApp/WeatherApp.xcodeproj/xcuserdata/orlovvladimir.xcuserdatad/xcschemes/WeatherApp.xcscheme new file mode 100644 index 0000000..ff97107 --- /dev/null +++ b/WeatherApp/WeatherApp.xcodeproj/xcuserdata/orlovvladimir.xcuserdatad/xcschemes/WeatherApp.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WeatherApp/WeatherApp.xcodeproj/xcuserdata/orlovvladimir.xcuserdatad/xcschemes/xcschememanagement.plist b/WeatherApp/WeatherApp.xcodeproj/xcuserdata/orlovvladimir.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..435fafd --- /dev/null +++ b/WeatherApp/WeatherApp.xcodeproj/xcuserdata/orlovvladimir.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + WeatherApp.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 9D859AFE1D9E31D30055F23A + + primary + + + + + diff --git a/WeatherApp/WeatherApp/Controller/ForecastViewController.swift b/WeatherApp/WeatherApp/Controller/ForecastViewController.swift index 5913480..c5a1aae 100644 --- a/WeatherApp/WeatherApp/Controller/ForecastViewController.swift +++ b/WeatherApp/WeatherApp/Controller/ForecastViewController.swift @@ -46,7 +46,7 @@ class ForecastViewController: UITableViewController, LocationDelegate, ProviderD self.navigationItem.title = self.navigationItem.title! + " (" + city! + ")" } - provider = WeatherProvider.weatherProvider(forService: .Yahoo, location: city!) + provider = WeatherProvider.weatherProvider(forService: currentService, location: city!) provider!.delegate = self } diff --git a/WeatherApp/WeatherApp/Controller/WeatherSourceViewController.swift b/WeatherApp/WeatherApp/Controller/WeatherSourceViewController.swift new file mode 100644 index 0000000..687a2c5 --- /dev/null +++ b/WeatherApp/WeatherApp/Controller/WeatherSourceViewController.swift @@ -0,0 +1,71 @@ +// +// WeatherSourceViewController.swift +// WeatherApp +// +// Created by Vladimir Orlov on 17.01.17. +// Copyright © 2017 VSU. All rights reserved. +// + +import UIKit + +class WeatherSourceViewController: UITableViewController { + + @IBOutlet var sourceTableView: UITableView! + + var services = [SupportedServices]() + + override func viewDidLoad() { + super.viewDidLoad() + + sourceTableView.delegate = self + sourceTableView.dataSource = self + self.getAllServices() + } + + private func getAllServices() { + for service in SupportedServices.allValues { + services.append(SupportedServices(rawValue: service.rawValue)!) + } + } + + // MARK: - Table view data source + + override func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return services.count + } + + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cellIdentifier = "cell" + let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) + cell.textLabel?.text = services[indexPath.row].rawValue + cell.accessoryType = .none + if cell.textLabel?.text == currentService.rawValue { + cell.accessoryType = .checkmark + } + + return cell + } + + // MARK: - UITableViewDelegate + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + + let chosenService = tableView.cellForRow(at: indexPath)! as UITableViewCell + let text = chosenService.textLabel?.text + + for service in SupportedServices.allValues { + if text == service.rawValue { + currentService = service + } + } + chosenService.accessoryType = .checkmark + tableView.deselectRow(at: indexPath, animated: true) + tableView.reloadData() + } + +} diff --git a/WeatherApp/WeatherApp/Model/Network/BaseWeatherService.swift b/WeatherApp/WeatherApp/Model/Network/BaseWeatherService.swift index b02e367..17c480e 100644 --- a/WeatherApp/WeatherApp/Model/Network/BaseWeatherService.swift +++ b/WeatherApp/WeatherApp/Model/Network/BaseWeatherService.swift @@ -8,9 +8,11 @@ import Foundation -enum SupportedServices { - case Yahoo - case OpenWeatherMap +enum SupportedServices: String { + case Yahoo = "Yahoo" + case OpenWeatherMap = "OpenWeatherMap" + + static let allValues = [Yahoo, OpenWeatherMap] } class BaseWeatherService : WeatherServiceProtocol { diff --git a/WeatherApp/WeatherApp/View/Main.storyboard b/WeatherApp/WeatherApp/View/Main.storyboard index 2c4ac34..f754afd 100644 --- a/WeatherApp/WeatherApp/View/Main.storyboard +++ b/WeatherApp/WeatherApp/View/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -136,11 +136,11 @@ - +