nike3203

Member

Last active 11 months ago

  1. 11 months ago
    Sun Mar 27 14:54:35 2016
    nike3203 started the conversation Access to variables from a target in swift.

    I have some variables in ViewController.swift file which is located in root of the application (default location) and I want to use them in KeyboardViewController.swift file which is located in custom keyboard target

    how can I access those variables?

    for being more clear I want to access the variables I have declared in ViewController.swift from a view controller in a target.

    ViewController.swift
    import UIKit

    public var globalVar = "defaultColor"

    class ViewController: UIViewController {

    @IBAction func buttonA(sender: UIButton) {

    globalVar = "ColorA"

    }

    @IBAction func buttonB(sender: UIButton) {

    globalVar = "ColorB"

    }

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
    }

    }
    KeyboardViewController.swift
    import UIKit

    class KeyboardViewController: UIInputViewController {

    override func updateViewConstraints() {
    super.updateViewConstraints()

    // Add custom view sizing constraints here
    }

    override func viewDidLoad() {
    super.viewDidLoad()

    if (globalVar == "defaultColor" /* The error is here it says use of unresolverd identifier 'globalVar' */) {

    } else if (globalVar == "ColorA") {

    } else if (globalVar == "ColorB") {

    }

    }

    }

  2. Sun Mar 27 14:44:51 2016
    nike3203 joined the forum.