TableView didSelectRowAt

swift
tableview

#1

Уважаемые форумчане, такой вопрос, пытаюсь сделать переход при нажатии на ячейку, на другой VC, причем на совершенно разные, как оформить массив функций, чтобы можно было вызывать функцию по индексу и массива!?

//структура данных для ячеек
    struct Object {
        var name: String!
        var image: UIImageView?
        var transition: ()
        init(_ n: String, _ i: UIImageView?, _ fucn: ()) {
            self.name = n
            self.image = i
            transition = fucn
        }
    }

//массив структур
var objectArray = [[Object]]()
func creatObjectList() {
        objectArray = [[ Object("Имя", nil, transitionNotificationSettingController())], [
            Object("Имя", nil, transitionNotificationSettingController()),
            Object("Имя", nil, transitionNotificationSettingController()),
            Object("Имя", nil, transitionNotificationSettingController()),
            Object("Имя", nil, transitionNotificationSettingController()) ]]
    }
//tableview
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        objectArray[indexPath.section][indexPath.row].transition
    }

Примерно так это выглядит сейчас, но выдает ошибку: Expression resolves to an unused l-value


#2

Попробуйте так

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let _ = objectArray[indexPath.section][indexPath.row].transition
    }

#3
let dict: [IndexPath: () -> Void] = [
    [0, 0]: {
        print("section: 0, row: 0")
    },
    [0, 1]: {
        print("section: 0, row: 1")
    },
    [1, 0]: {
        print("section: 1, row: 0")
    },
    [1, 1]: {
        print("section: 1, row: 1")
    }
]

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    dict[indexPath]?()
}

Обычно делают как то так:

func showVc(from indexPath: IndexPath) {
    switch indexPath {
    case [0, 0]:
        performSegue(withIdentifier: "", sender: nil)
    case [0, 1]:
        performSegue(withIdentifier: "", sender: nil)
    case [1, 0]:
        performSegue(withIdentifier: "", sender: nil)
    case [1, 1]:
        performSegue(withIdentifier: "", sender: nil)
    default:
        break
    }
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    showVc(from: indexPath)
}