문제 해결 기록

UIAlertController의 present 중복 문제

if !self.alert.isBeingPresented {
    self.alert.message = self.apiManager.errorHandler(error: error)
    self.present(self.alert, animated: true, completion: nil)
}

NSLayoutConstraint 변경

// 변수로 선언 후, NSLayoutConstraint.activate([])로 다른 뷰들의 제약을 설정해줄때, 적절한 곳에 넣음
private lazy var trailingOfSearchTextField: NSLayoutConstraint = searchTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -8)

@IBAction func touchUpCancelButton(_ sender: UIButton) {
       searchTextField.text = ""
       searchTextField.resignFirstResponder()
}
func textFieldDidBeginEditing(_ textField: UITextField) {
    UIView.animate(withDuration: 0.2) {
        self.trailingOfSearchTextField.constant = -50
        self.view.layoutIfNeeded()
    }
}

func textFieldDidEndEditing(_ textField: UITextField, reason: UITextField.DidEndEditingReason) {
    UIView.animate(withDuration: 0.2) {
        self.trailingOfSearchTextField.constant = -8
        self.view.layoutIfNeeded()
    }
}

UITableView안에 UICollectionView 넣을 때, 데이터 전달하기

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: WeatherForecastTableViewCell.identifier, for: indexPath) as? WeatherForecastTableViewCell else { return UITableViewCell() }

        cell.dayLabel.text = dayList[indexPath.row]
        cell.setUpForecast(forecast: forecasts[indexPath.row])

        return cell
    }

// 전달받을 변수
private var forecast: Forecast?

override func prepareForReuse() {
    super.prepareForReuse()
    forecast = nil
}

// prepare를 통해서 테이블뷰의 indexPath.row마다 다른 데이터를 적용
func setUpForecast(with forecast: Forecast) {
    self.forecast = forecast
}