how can I store a variable(Int) permanently after app closes and Display it? : I am trying to store a variable named *total* which holds the number of rows in UItableView. Since the user types strings for UITableView, the variable is *listTable* which is String array.

I have my *total* as total = listTable.count

ISSUE:

Every time the app launches it displays 0 as number of rows used, however once you go to the UITableView ViewController and come back to the main ViewController it automatically corrects its self to the current amount of rows.

Code Used:


   

     import UIKit
        var listTable = [String]()
        var total = listTable.count
        class ViewController: UIViewController, UITextFieldDelegate {
           
            @IBOutlet weak var numberOfRows: UILabel!
            @IBOutlet weak var TypeToCreateRow: UITextField!
            @IBOutlet weak var AddRow: UIButton!
            
            override func viewDidLoad() {
                super.viewDidLoad()
                total = listTable.count
         
                NSUserDefaults.standardUserDefaults().setObject(total, forKey: "rows")
                
                let showRow =    NSUserDefaults.standardUserDefaults().objectForKey("rows")!
                numberOfRows.text = "\(showRow)"
                print(showRow)
             
                
              
                // Do any additional setup after loading the view, typically from a nib.
            }
     @IBAction func RowAdd(sender: UIButton) {
                listTable.append(TypeToCreateRow.text!)
                
                TypeToCreateRow.text = " "
              
                
               numberOfRows.text = "\(total)" }

