Skip to content

Commit

Permalink
Add some description and fixed location manager
Browse files Browse the repository at this point in the history
  • Loading branch information
thefiltitoff committed Jul 26, 2022
1 parent b005c86 commit 402d411
Showing 1 changed file with 46 additions and 44 deletions.
90 changes: 46 additions & 44 deletions WeatherApp/ViewControllers/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ViewController: UIViewController {

if CLLocationManager.locationServicesEnabled() {
locationManager.requestLocation()
locationManager.startUpdatingLocation()
}
}

Expand All @@ -60,13 +61,52 @@ class ViewController: UIViewController {
//MARK: - Fetching Data
private func getData(requestType: RequestType) {
// Parsing with URLSession
NetworkManager.shared.fetchCurrentWeather(
dataType: CurrentWeather.self,
forRequestType: requestType
) { [unowned self] result in
switch result {

case .success(let currentWeather):
self.startAnimating()
self.updateUI(with: currentWeather)
case .failure(let error):
self.presentUIAlertController(
withTitle: "Error",
andMessage: error.rawValue,
style: .alert,
withSearch: false,
completionHandler: nil
)
}
}

// Parsing with Alamofire Decodable
/*
AlamofireNetworkManager.shared.fetchCurrentWeather(
forRequestType: requestType) { result in
switch result {
case .success(let currentWeather):
self.startAnimating()
self.updateUI(with: currentWeather)
case .failure(let error):
self.presentUIAlertController(
withTitle: "Error",
andMessage: error.rawValue,
style: .alert,
withSearch: false,
completionHandler: nil
)
}
}
*/

// Parsing with Alamofire with manually parsing
//It's just for understading how decode method works
/*
NetworkManager.shared.fetchCurrentWeather(
dataType: CurrentWeather.self,
forRequestType: requestType
) { [unowned self] result in
AlamofireNetworkManager.shared.fetchCurrentWeatherWithJSONParsing(
forRequestType: requestType) { result in
switch result {
case .success(let currentWeather):
self.startAnimating()
self.updateUI(with: currentWeather)
Expand All @@ -78,48 +118,10 @@ class ViewController: UIViewController {
withSearch: false,
completionHandler: nil
)
}
}
*/

// Parsing with Alamofire Decodable
/*
AlamofireNetworkManager.shared.fetchCurrentWeather(
forRequestType: requestType) { result in
switch result {
case .success(let currentWeather):
self.startAnimating()
self.updateUI(with: currentWeather)
case .failure(let error):
self.presentUIAlertController(
withTitle: "Error",
andMessage: error.rawValue,
style: .alert,
withSearch: false,
completionHandler: nil
)
}
}
*/

// Parsing with Alamofire without automatic
AlamofireNetworkManager.shared.fetchCurrentWeatherWithJSONParsing(
forRequestType: requestType) { result in
switch result {
case .success(let currentWeather):
self.startAnimating()
self.updateUI(with: currentWeather)
case .failure(let error):
self.presentUIAlertController(
withTitle: "Error",
andMessage: error.rawValue,
style: .alert,
withSearch: false,
completionHandler: nil
)

}
}
}
}

Expand Down

0 comments on commit 402d411

Please sign in to comment.