条件二元运算符错误

Binary operator error on condition

我想在 pickerview 行上给出条件,但它只是给我错误。 二元运算符不能应用于操作数

let viewList: [String] = ["Fixed", "Recurring"]

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    if (viewList[row] == 0) {

    }
}

更新答案

尝试这样做:

class MyViewController: UIViewController {
    fileprivate let viewList: [String] = ["Fixed", "Recurring"]
}

// MARK: - UIPickerViewDelegate
extension MyViewController: UIPickerViewDelegate {
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
            print("Selected value \(viewList[row]) at row \(row)")

            if viewList[row] == "Fixed" {
                print("Fixed has been selected!")
            }
    }
}

问题来自您的情况,请尝试以下代码。

更多信息:Apple Documentation - Collection Types