-
Notifications
You must be signed in to change notification settings - Fork 26
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
날씨 앱 [STEP 1] yujeong #39
base: rft_3_yujeong
Are you sure you want to change the base?
날씨 앱 [STEP 1] yujeong #39
Conversation
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "WeatherCell", for: indexPath) | ||
|
||
guard let cell: WeatherTableViewCell = cell as? WeatherTableViewCell, | ||
let weatherForecastInfo = delegate?.getWeatherForecastInfo(row: indexPath.row) else { | ||
return cell | ||
} | ||
|
||
setCellLabel(cell: cell, weatherForecastInfo: weatherForecastInfo) | ||
|
||
let iconName: String = weatherForecastInfo.weather.icon | ||
let urlString: String = "https://openweathermap.org/img/wn/\(iconName)@2x.png" | ||
|
||
|
||
if let image = delegate?.getImageChacheObject(urlString: weatherForecastInfo.weather.icon) { | ||
cell.weatherIcon.image = image | ||
return cell | ||
} | ||
|
||
Task { | ||
guard let url: URL = URL(string: urlString), | ||
let (data, _) = try? await URLSession.shared.data(from: url), | ||
let image: UIImage = UIImage(data: data) else { | ||
return | ||
} | ||
|
||
delegate?.setImageChacheObject(image: image, urlString: urlString) | ||
|
||
if indexPath == tableView.indexPath(for: cell) { | ||
cell.weatherIcon.image = image | ||
} | ||
|
||
} | ||
|
||
return cell | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "WeatherCell", for: indexPath) | |
guard let cell: WeatherTableViewCell = cell as? WeatherTableViewCell, | |
let weatherForecastInfo = delegate?.getWeatherForecastInfo(row: indexPath.row) else { | |
return cell | |
} | |
setCellLabel(cell: cell, weatherForecastInfo: weatherForecastInfo) | |
let iconName: String = weatherForecastInfo.weather.icon | |
let urlString: String = "https://openweathermap.org/img/wn/\(iconName)@2x.png" | |
if let image = delegate?.getImageChacheObject(urlString: weatherForecastInfo.weather.icon) { | |
cell.weatherIcon.image = image | |
return cell | |
} | |
Task { | |
guard let url: URL = URL(string: urlString), | |
let (data, _) = try? await URLSession.shared.data(from: url), | |
let image: UIImage = UIImage(data: data) else { | |
return | |
} | |
delegate?.setImageChacheObject(image: image, urlString: urlString) | |
if indexPath == tableView.indexPath(for: cell) { | |
cell.weatherIcon.image = image | |
} | |
} | |
return cell | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
guard let cell = tableView.dequeueReusableCell(withIdentifier: "WeatherCell", for: indexPath) as? WeatherTableViewCell, | |
let weatherForecastInfo = delegate?.getWeatherForecastInfo(row: indexPath.row) else { | |
return UITableViewCell() | |
} | |
setCellLabel(cell: cell, weatherForecastInfo: weatherForecastInfo) | |
updateWeatherIcon(for: cell, at: indexPath, with: weatherForecastInfo.weather.icon) | |
return cell | |
} | |
func updateWeatherIcon(for cell: WeatherTableViewCell, at indexPath: IndexPath, with iconName: String) { | |
let urlString = "https://openweathermap.org/img/wn/\(iconName)@2x.png" | |
if let image = delegate?.getImageChacheObject(urlString: iconName) { | |
cell.weatherIcon.image = image | |
return | |
} | |
Task { | |
guard let url = URL(string: urlString), | |
let (data, _) = try? await URLSession.shared.data(from: url), | |
let image = UIImage(data: data) else { | |
return | |
} | |
delegate?.setImageChacheObject(image: image, urlString: iconName) | |
if tableView.indexPath(for: cell) == indexPath { | |
cell.weatherIcon.image = image | |
} | |
} | |
} |
이런식으로 쪼개 볼 수 있을것 같긴하네요.
func setCellLabel(cell: WeatherTableViewCell, weatherForecastInfo: WeatherForecastInfo) { | ||
cell.weatherLabel.text = weatherForecastInfo.weather.main | ||
cell.descriptionLabel.text = weatherForecastInfo.weather.description | ||
cell.temperatureLabel.text = "\(weatherForecastInfo.main.temp)\( delegate?.getTempUnit() ?? "")" | ||
|
||
let date: Date = Date(timeIntervalSince1970: weatherForecastInfo.dt) | ||
cell.dateLabel.text = delegate?.convertDateToString(date: date) | ||
} | ||
|
||
func setCellImage(cell: WeatherTableViewCell, weatherForecastInfo: WeatherForecastInfo) { | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
윗 부분에서 나눈것과 별개로 셀의 어떠한 부분들을 변경하는것이라면 Cell이 해당 메서드를 가지는게 좋을것 같아 보입니다.
셀에는 필요한 데이터들만 넘겨주고, 셀에서 직접 변경하도록 말이죠
|
||
var delegate: WeatherViewDelegate? | ||
|
||
func setTableView(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set보다는 configure 같은 네이밍은 어떠신가요?
func refreshNavigationTitle(title: String) | ||
} | ||
|
||
final class WeatherInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class의 이름이 모델처럼 느껴져서, JSON을 fetch하는 객체가 느껴지도록 하면 좋을 것 같아요!
print(error.localizedDescription) | ||
return nil | ||
} | ||
delegate.refreshNavigationTitle(title: info.city.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetchWeatherJSON와는 관련이 없는 로직인것 같은데 따로 메서드로 빼보면 어떨까요?
컴플리션 핸들러를 통해서 WeatherForecastViewController 에서도 사용가능할것 같기도 하네요.
@uuu1101 프로토콜 관련한 부분은 아직 익히는 중이라 시간안에 적용은 못했지만 리뷰해주신대로 혼자서라도 꼭 적용해보겠습니다!! 감사합니다
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
간단한 코멘트 몇가지 남겼습니다. 3주간 고생많으셨습니다 !
func refreshNavigationTitle(title: String) | ||
} | ||
|
||
final class WeatherInfo { | ||
final class FetchWeatherInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
데이터 타입에 동사형이 들어가서 함수로 생각될 수 있을것 같아요. 오히려 기존의 WaetherInfo
가 더 좋은 네이밍 같습니다!
@@ -36,7 +36,14 @@ final class WeatherInfo { | |||
print(error.localizedDescription) | |||
return nil | |||
} | |||
delegate.refreshNavigationTitle(title: info.city.name) | |||
Task { @MainActor in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MainActor도 사용하셨군요 ! 👍
@@ -100,4 +100,15 @@ class WeatherTableViewCell: UITableViewCell { | |||
weatherLabel.text = "~~~" | |||
descriptionLabel.text = "~~~~~" | |||
} | |||
|
|||
func setCellLabel(weatherForecastInfo: WeatherForecastInfo, tempUnit: String, dateStr: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
많이 길지 않아서 dateStr
라고 축약하는것 보단 dateString
이 더 좋은것 같습니다.
setCellLabel(for: cell, with: weatherForecastInfo) | ||
updateWeatherIcon(for: cell, at: indexPath, with: weatherForecastInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메서드로 잘 나눠 주셨네요 👍🏻
func setCellLabel(for cell: WeatherTableViewCell, with weatherForecastInfo: WeatherForecastInfo) { | ||
let tempUnit = delegate?.getTempUnit() ?? "" | ||
let date: Date = Date(timeIntervalSince1970: weatherForecastInfo.dt) | ||
let dateStr = delegate?.convertDateToString(date: date) ?? "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앞서 드린 리뷰내용과 동일합니다 dateStr
@uuu1101
안녕하세요!
이번 미션에서는 ViewController 클래스의 책임이 많은 것 같아서 protocol을 이용해서 분리하였고
내용이 많은 메서드 들도 분리해서 구현해봤습니다
또한 그런 과정에서 ViewController 와 View도 나눠서 View 부분에서는 View에 보여지는 부분에 대한 처리를 하도록 분리하였습니다
조언을 얻고싶은 부분