lundi 6 juillet 2015

Passing global variables in .swift to specific viewController

I want to pass a global array(in .swift file) to specific ViewController. Here's my code

commonData.swift

import Foundation

var regionArray:[Bool]?

let region = [
"United States",
"United Kingdom"
]

testTableViewController.swift

import UIKit

var arraySize:Int?
var boolArray:[Bool]?

class testTableViewController: UITableViewController {
    override func viewDidLoad() {
        self.boolArray = regionArray
        self.arraySize = region.count

        if(self.boolArray == nil) {
             self.boolArray = Array(count: self.arraySize!, repeatedValue: false)
             NSLog("Array renewed")
        }
    }
}

Even though I tried to enter table view many times, regionArray in commonData.swift prints out "Array renewed" in log data. How can I set and pass a global variable to load/make into specific viewController?

Aucun commentaire:

Enregistrer un commentaire