Segue is not working

I have parsed a json file with the following structure into a table view succesfully.

import Foundation

struct ActionResult: Codable {

    let data3: [Datum]

}

struct Datum: Codable {

    let actionGoal, actionGoalDescription, actionGoalImage: String

    let actions: [Action]

}

struct Action: Codable {

    let actionTitle: String

    let actionID: Int

    let select, completed, favorite: Bool

    let actionType, actionDescription, actionTips, actionImage: String

    let actionSponsor, actionSponsorURL: String

Now I am preparing a segue to a detail ViewController but is giving me an error.

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

            performSegue(withIdentifier: "showDetail", sender: self)

       }

        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

            if let destination = segue.destination as? ActionDetailViewController {

                destination.action = result?.data3.actions[(tableView.indexPathForSelectedRow?.row)!]

Error description. Value of type '[Datum]' has no member 'actions' Who can help me?

Additional info: DetailViewController set up

import UIKit

import SwiftUI

class ActionDetailViewController: UIViewController {

    @IBOutlet weak var ActionImageDetail: UIImageView!

    @IBOutlet weak var ActionTitleDetail: UILabel!

    @IBOutlet weak var ActionDescriptionDetail: UITextView!

    @IBOutlet weak var ActionTipsDetail: UITextView!

    

    var action: Action?

    

    override func viewDidLoad() {

        super.viewDidLoad()

        ActionTitleDetail.text = action?.actionTitle

        ActionImageDetail.image = UIImage(named: action!.actionImage)

        ActionDescriptionDetail.text = action?.actionDescription

        ActionTipsDetail.text = action?.actionTips

             

          }

   

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

    }

}

Answered by MobileTen in 709232022

data3 is a collection type of Datums. result?.data3[index].actions[(tableView.indexPathForSelectedRow?.row)!]

Accepted Answer

data3 is a collection type of Datums. result?.data3[index].actions[(tableView.indexPathForSelectedRow?.row)!]

The segue is working if I add:

var indexdata = 0

and add at didSelectRow

indexdata = 0

but the first row in the second section in the segue is showing the detail of the first section.

Segue is not working
 
 
Q