I am trying to send multiple objects from my initial view controller to my Username VC
. Here is the segue code from my controllers: The issue comes when I add in the code to send the second object, termreport
. If I delete the termsM
and the assignment, it send the students as usually, but I also need to send the termReport
object. How would I fix this?
ViewControler:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let students = sender as AnyObject as? [Student]
else { return }
guard let termsM = sender as AnyObject as? [TermReport] //How would I send both objects?
else { return }
if let secondVC = segue.destination as? UsernameVC {
secondVC.students = students
secondVC.userWebView = webView
secondVC.terms = termsM // not sending
}
let gradeResponse = try Parser(innerHTML)
self.performSegue(withIdentifier: "ShowStudents", sender: gradeResponse.students)
self.performSegue(withIdentifier: "ShowStudents", sender: gradeResponse.termReports) //how would I send both variables?
UsernameVC:
var terms: [TermReport]!
override func viewDidLoad() {
print("TERM \(terms[0].grades[3])")//returns found nil optional ERROR
}
You have to include all of the variables you want to send to another
ViewController
using a segue into a single object (which can be a collection as well). You either create a custom class/struct that has properties with type[Student]
and[TermReport]
or put these into a native collection (Tuple or Dictionary).Create custom struct: