If you're using storyboards, typically you'll use a segue to link from one view controller to another. In that case, prepareForSegue is the usual place to pass info from one view controller to another.
You need to create a property in the destination view controller to receive the array.
If you add a property array
of custom type YourArrayType
, to ViewControllerHistory
, the first part of that class might look like this:
class ViewControllerHistory: UIViewController {
var array: YourArrayType
}
And then the code in the first view controller might look like this:
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let destination = segue.destination as? ViewControllerHistory else
{
return
}
destination.array = arrayWithResults
}
A couple of notes:
Don't use arrays of AnyObject type. Swift supports arrays containing specific types of objects. You should prefer arrays of a specific type over arrays of AnyObject
Variable names should start with a lower case letter. Class names and types should start with an upper-case letter. Therefore your ArrayWithResults
should be arrayWithResults
instead.
If you're invoking your ArrayWithResults
view controller directly rather than with a segue, you can simply create the view controller using instantiateViewController(withIdentifier:)
, set the property, then present or push it.