Skip to content

Commit

Permalink
presenter を介して View の操作を行う
Browse files Browse the repository at this point in the history
  • Loading branch information
askldfghj committed Jan 17, 2024
1 parent 91d290a commit d83e59d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ios-training-bjung/Presenters/HomePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ protocol HomePresenterInput {
}

protocol HomePresenterOutput: AnyObject {
@MainActor
func showLoadingUI()
@MainActor
func updateInfoDisplay(updatedInfo response: WeatherResponse)
@MainActor
Expand All @@ -38,6 +40,7 @@ final class HomePresenter: HomePresenterInput {
// API 通信が課題なのであえて async await を使って表現
Task {
do {
view?.showLoadingUI()
let request = WeatherRequest(area: "tokyo", date: Date())
let response = try await model.fetchWeatherData(request: request)

Expand Down
8 changes: 5 additions & 3 deletions ios-training-bjung/Views/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ final class HomeViewController: UIViewController {
}

func loadWeatherData() {
indicator.startAnimating()
reloadButton.isEnabled = false
presenter.loadWeatherData()
}

Expand All @@ -56,7 +54,6 @@ final class HomeViewController: UIViewController {
}

@IBAction func onReloadButtonClick(_ sender: UIButton) {
indicator.startAnimating()
loadWeatherData()
}

Expand Down Expand Up @@ -84,6 +81,11 @@ final class HomeViewController: UIViewController {

extension HomeViewController: HomePresenterOutput {

func showLoadingUI() {
indicator.startAnimating()
reloadButton.isEnabled = false
}

func updateInfoDisplay(updatedInfo response: WeatherResponse) {
let resource = getDisplayResource(response: response.weatherCondition)

Expand Down

0 comments on commit d83e59d

Please sign in to comment.