dimanche 28 juin 2015

Xcode swift: global variable is empty

here is my code that did not work:

AppDelegate.swift

import UIKit

var systemLanguage = ""

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        // Systemsprache erkennen
        let systemLanguage = NSLocale.preferredLanguages()[0] as! String
        println("Device system language: \(systemLanguage)")

        return true
    }

settingsTableViewController.swift

override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationController!.navigationBar.barStyle = UIBarStyle.Black
        self.navigationController!.navigationBar.tintColor = UIColor.whiteColor()

        if systemLanguage == "de" {

            self.title = "Einstellungen"

        } else {

            self.title = "Settings"

        }
        println("Device system language: \(systemLanguage)")

        self.tableView.backgroundColor = UIColor.darkGrayColor()

    }

When the app is starting the console says: Device system language: de

but when I change the view to settingsTableViewController the variable systemLanguage is empty. The console says: Device system language:

Why does it happen?

Aucun commentaire:

Enregistrer un commentaire