У меня есть массив, который выглядит следующим образом:
[Category(title: "First Category", question: [
Question(
title: "1 Question",
article: "1 Arcticle",
anwser: "Answer",
link: "google.com",
favorite: false,
possibleAnswers: ["First", "Second", "Third", "Fourth"],
rightAnswerNumber: 2), etc..]),
etc..]
Я не понимаю, как извлечь данные в следующем ViewController. Здесь у меня есть код
В родителе:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == ListViewController.className() {
let indexPath = tableView.indexPathForSelectedRow
let destinationVC = segue.destination as? ListViewController
var data: Category
if isFiltering() {
data = filteredData[indexPath!.row]
} else {
data = dataSource[indexPath!.row]
}
destinationVC?.passedData = data
}
}
у ребенка:
var passedData: Category?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: ListTableViewCell.identifier(), for: indexPath) as! ListTableViewCell
cell.passedData = passedData![indexPath.row][indexPath.row] //Here
cell.selectionStyle = .gray
return cell
}
Мне нужно, чтобы cell.passedData принимал массив Вопросов в категории, зависит от indexPath, но не знаю как.
Я думал о извлечении массива из категории с помощью цикла for, но не понял, как.