Last active
March 20, 2022 13:40
-
-
Save metin-atalay/8ae645d080ae17c76f1b6d2721fa8132 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PKHUD | |
class WeatherListViewController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
var presenter: WeatherListPresenterProtocol? | |
var weatherList: [WeatherModel] = [] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
presenter?.viewDidLoad(cityName: "istanbul") // Default City | |
} | |
} | |
extension WeatherListViewController: WeatherListViewProtocol { | |
func showWeatherInfo(weathers: WeatherModel) { | |
weatherList.append(weathers) | |
self.tableView.reloadData() | |
} | |
func showError() { | |
HUD.flash(.label("An error occured"), delay: 2.0) | |
} | |
func showLoading() { | |
HUD.show(.progress) | |
} | |
func hideLoading() { | |
HUD.hide() | |
} | |
} | |
extension WeatherListViewController: UITableViewDataSource, UITableViewDelegate { | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "WeatherCell", for: indexPath) as! WheatherTableViewCell | |
let wather = weatherList[indexPath.row] | |
cell.set(forWeather: wather) | |
return cell | |
} | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return weatherList.count | |
} | |
} | |
extension WeatherListViewController: AddWeatherDelegate { | |
func addWeatherDidSave(cityName: String) { | |
presenter?.viewDidLoad(cityName: cityName) | |
} | |
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
if segue.identifier == "AddWheatherCityViewController" { | |
guard let addWeathercityVC = segue.destination as? AddWheatherCityViewController else { | |
fatalError("navigation not found") | |
} | |
addWeathercityVC.delegate = self | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment