I have an app which goes something like this:
first screen loads a collection view, the items that are displayed are kept in a csv file.
you click on one of the items and it loads a new screen, with details from the csv about that item.
I have a csv parse tool, which does a great job of pulling the correct information based on the id of that row in the csv file.
my issue: after the second screen, i have a 3rd screen whcih has a Google Map view, one of the items in the csv file is lat and another lon.
I want to pass the lat and lon values through to the third screen based on the id, so the correct values go through.
I am very new to Swift and I just can't get my head around this one.
1) do I need to parse the CSV file again on the second screen?
2) do I send the details from the already parsed CSV file in the prepare for Segue method? if so can somebody help me code the prepare for segue please
edited to incude code:
first VC prepare for Segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "TrackDetailVC" {
if let detailsVC = segue.destination as? TrackDetailVC {
if let tr = sender as? Tracks {
detailsVC.track = tr
}
}
}
first VC CSV Parse code
func parseTrackCSV() {
let path = Bundle.main.path(forResource: "tracks", ofType: "csv")!
do {
let csv = try CSV(contentsOfURL: path)
let rows = csv.rows
for row in rows {
let trackId = Int(row["id"]!)!
let name = row["name"]!
let postcode = row["postcode"]!
let trackType = row["type"]!
let locID = row["locID"]!
let lon = Double(row["long"]!)!
let lat = Double(row["lat"]!)!
let tr = Tracks(name: name, trackId: trackId, postcode: postcode, trackType: trackType, locId: locID, lon: lon, lat: lat)
track.append(tr)
}
} catch let err as NSError {
print(err.debugDescription)
}
}
so using this how would I write the Prepare for Segue code on the second VC to pass through to the 3rd?
many thanks