Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавлен контроллер с выбором источника погоды #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Binary file modified WeatherApp/.DS_Store
Binary file not shown.
16 changes: 12 additions & 4 deletions WeatherApp/WeatherApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -47,11 +49,13 @@
/* Begin PBXFileReference section */
0802D1FE1DE9DCAF00054425 /* DayForecastViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DayForecastViewController.swift; sourceTree = "<group>"; };
0802D2011DE9DEE700054425 /* WeatherState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherState.swift; sourceTree = "<group>"; };
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 = "<group>"; };
6D1F340D1DF84D0600714FD6 /* TodayViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TodayViewCell.swift; sourceTree = "<group>"; };
843CFBA71E1FFFEF008463E6 /* menu.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = menu.png; sourceTree = "<group>"; };
843CFBA91E200469008463E6 /* CityPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CityPickerViewController.swift; sourceTree = "<group>"; };
84E7C9A71E2970790027489E /* OpenWeatherMapService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenWeatherMapService.swift; sourceTree = "<group>"; };
99A789FF1E3001690037292D /* WeatherService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WeatherService.swift; path = ../../../../../Projects/WeatherApp/WeatherApp/WeatherApp/Model/Helpers/WeatherService.swift; sourceTree = "<group>"; };
99A78A011E3002590037292D /* add_2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = add_2x.png; path = ../../../../Downloads/add_2x.png; sourceTree = "<group>"; };
99A78A031E3005F30037292D /* WeatherSourceViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherSourceViewController.swift; sourceTree = "<group>"; };
9D42497A1DBB8E0A00125040 /* ForecastMO+ForecastObjectProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "ForecastMO+ForecastObjectProtocol.swift"; path = "../../../Providers/ForecastMO+ForecastObjectProtocol.swift"; sourceTree = "<group>"; };
9D6A14531DBA83EA00715576 /* CoreDataProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataProtocol.swift; sourceTree = "<group>"; };
9D6A14551DBA85AD00715576 /* ProviderProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProviderProtocol.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -105,8 +109,8 @@
843CFBA61E1FFFD8008463E6 /* Images */ = {
isa = PBXGroup;
children = (
99A78A011E3002590037292D /* add_2x.png */,
843CFBA71E1FFFEF008463E6 /* menu.png */,
4D5C914C1E2CE3CD005D947F /* add_2x.png */,
);
name = Images;
sourceTree = "<group>";
Expand Down Expand Up @@ -181,6 +185,7 @@
0802D1FE1DE9DCAF00054425 /* DayForecastViewController.swift */,
843CFBA91E200469008463E6 /* CityPickerViewController.swift */,
6D1F340D1DF84D0600714FD6 /* TodayViewCell.swift */,
99A78A031E3005F30037292D /* WeatherSourceViewController.swift */,
);
path = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -247,6 +252,7 @@
9DCF9BB31DBA4286007518CC /* Helpers */ = {
isa = PBXGroup;
children = (
99A789FF1E3001690037292D /* WeatherService.swift */,
9DCF9BB41DBA4286007518CC /* Units.swift */,
);
name = Helpers;
Expand Down Expand Up @@ -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;
};
Expand All @@ -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 */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WeatherApp/Model/Providers/WeatherProvider.swift"
timestampString = "506509313.997025"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "86"
endingLineNumber = "86"
landmarkName = "requestData()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9D859AFE1D9E31D30055F23A"
BuildableName = "WeatherApp.app"
BlueprintName = "WeatherApp"
ReferencedContainer = "container:WeatherApp.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9D859AFE1D9E31D30055F23A"
BuildableName = "WeatherApp.app"
BlueprintName = "WeatherApp"
ReferencedContainer = "container:WeatherApp.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9D859AFE1D9E31D30055F23A"
BuildableName = "WeatherApp.app"
BlueprintName = "WeatherApp"
ReferencedContainer = "container:WeatherApp.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9D859AFE1D9E31D30055F23A"
BuildableName = "WeatherApp.app"
BlueprintName = "WeatherApp"
ReferencedContainer = "container:WeatherApp.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>WeatherApp.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>9D859AFE1D9E31D30055F23A</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
71 changes: 71 additions & 0 deletions WeatherApp/WeatherApp/Controller/WeatherSourceViewController.swift
Original file line number Diff line number Diff line change
@@ -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()
}

}
8 changes: 5 additions & 3 deletions WeatherApp/WeatherApp/Model/Network/BaseWeatherService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading