How to append array data when switching classes (swift4)

My code below submits ints to an array the problem is when the user segues to another view controller and then segues back to the original view controller and tries to submit more ints it saves over the original ints that where already saved. EXAMPLE VC1 USERS SUBMITS 1,2 THEN USER GOES TO VC2 USER RETURNS TO VC1 AND SUBMITS 3. WHAT IS PRINTED OUT IS JUST 3. NOT 1,2, AND 3.

                   import UIKit

           class ViewController: UIViewController {
          @IBOutlet var txt: UITextField!
             var arrayOfInt = [Int]()

    @IBAction func submit(_ sender: Any) {
if let text = txt.text {
if let number = Int(text){


The problem is that you don’t actually store them. When you come back using segue, you have a new controller instead of previous one.

This topic was automatically closed after 166 days. New replies are no longer allowed.