struct WeatherTableCellViewModel {
var timeString: String
var cityString: String
var temperatureString: String
var weatherDetail: WeatherDetail
var isUserLocation: Bool // + 해당 셀이 현재 위치 정보를 담고 있는지에 대한 여부
}
func setContents(viewModel: WeatherTableCellViewModel) {
cityLabel.text = viewModel.cityString
temperature.text = viewModel.temperatureString
timeLabel.text = viewModel.timeString
// 해당 셀이 사용자 위치에 대한 정보를 담고 있고 마커 라벨이 없다면 마커를 생성하라.
if viewModel.isUserLocation && !hasMarkerLabel {
createMarker()
}
}
private func createMarker() {
let markerImageView = UIImageView(image: UIImage(named: "marker"))
addSubview(markerImageView)
markerImageView.contentMode = .scaleAspectFit
markerImageView.translatesAutoresizingMaskIntoConstraints = false
markerImageView.heightAnchor.constraint(equalTo: cityLabel.heightAnchor).isActive = true
markerImageView.trailingAnchor.constraint(equalTo: cityLabel.leadingAnchor, constant: -5).isActive = true
markerImageView.topAnchor.constraint(equalTo: cityLabel.topAnchor).isActive = true
hasMarkerLabel = true
}