I have an array that looks like:
[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..]
I don't understand how to extract data in next ViewController. Here I have a code In parent:
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
}
}
In child:
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
}
I need to make cell.passedData take an array of Question in Category depends from indexPath, but don't know how.
I was thinking about extracting array from Category using for loop, but didn't realize how.
cell.passedData?cell.passedDataof typeQuestionorString?