I have a struct called trip.
struct trip {
var name: String
var description: String
var elements: [Any] = []
mutating func addItemToElements(newValue: Any) {
elements.append(newValue)
}
}
As you can see, there is an array inside. I'm adding some other structs like element_flight into this array by function addItemtoElements.
struct element_flight {
var origin: String
var destination: String
var flightno: String
var departure: NSDate
var arrival: NSDate
var seat: String
}
Then I'm trying to create a list using table view:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "elementTrip", for: indexPath) as! CellInElementsOfTripsTableViewCell
let elem = trips[0].elements[indexPath.row]
cell.mainTextLabel.text = elem.origin //it doesn't work
retu cell
}
I can't get any of parts of struct (like origin in code). What am I doing wrong?
I'm creating similar structs to element_flight and it could be the best way to put it in one array and then show in table view.
