В этом PreferencesVC у меня есть два pickerView для пользователя, чтобы выбрать две валюты для отправки в основной интерфейс пользователя. Сохраняя изменения и отправляя данные, он говорит, что он неожиданно найден, ноль. Почему мои pickerViews всегда содержат данные из непустого кортежа?
protocol ChangeCurrencyDelegate {
func userEnteredNewCurrency(top: CurrencyTuple, bottom: CurrencyTuple)
}
class ExchangePreferencesVC: UIViewController {
@IBOutlet weak var topCurrencyLabel: UILabel!
@IBOutlet weak var topCurrencyPicker: UIPickerView!
@IBOutlet weak var bottomCurrencyLabel: UILabel!
@IBOutlet weak var bottomCurrencyPicker: UIPickerView!
var delegate: ChangeCurrencyDelegate?
var topPickerOptions = [(name: String, symbol: String, flag: UIImage)]()
var bottomPickerOptions = [(name: String, symbol: String, flag: UIImage)]()
var userCurrencyChoice: Currencies!
override func viewDidLoad() {
super.viewDidLoad()
topPickerOptions = currencyISOCode
bottomPickerOptions = currencyISOCode
}
// User top and bottom pickerView choices
func createTopAndBottomCurrency() {
let topUserIndex = topCurrencyPicker.selectedRow(inComponent: 0)
let bottomUserIndex = bottomCurrencyPicker.selectedRow(inComponent: 0)
let topUserChoice = currencyISOCode[topUserIndex]
let bottomUserChoice = currencyISOCode[bottomUserIndex]
userCurrencyChoice = Currencies(top: topUserChoice, bottom: bottomUserChoice)
}
// MARK: - Cancel and Save Changes actions
@IBAction func saveChanges(_ sender: Any) {
delegate?.userEnteredNewCurrency(top: userCurrencyChoice.top, bottom: userCurrencyChoice.bottom)
self.dismiss(animated: true, completion: nil)
}
}
делегат назначается таким образом ->
// MARK: - Delegate of the ChangeCurrency protocol
extension ExchangeRateViewController: ChangeCurrencyDelegate {
func userEnteredNewCurrency(top: CurrencyTuple, bottom: CurrencyTuple) {
self.topFlag.setImage(top.flag, for: .normal)
self.topSymbol.text = top.symbol
self.bottomFlag.setImage(bottom.flag, for: .normal)
self.bottomSymbol.text = bottom.symbol
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goToPreferences" {
let destinationVC = segue.destination as! ExchangePreferencesVC
destinationVC.delegate = self
}
}
}