I'm trying to create a settings view controller in my container app for my customKeyboard for iOS8 in Swift. I have create a Bool() and I got right what I need by that, but now i need to get the Keyboard target checking the bool value and I can't import the other swift file..
I've this code:
ViewControllerSettings.swift:
@IBOutlet weak var Switch1: UISwitch!
var dotOn = Bool()
override func viewDidLoad() {
super.viewDidLoad()
if NSUserDefaults.standardUserDefaults().boolForKey("dotOn") == true {
Switch1.setOn(true, animated: true)
} else {
Switch1.setOn(false, animated: true)
}
@IBAction func backSave(sender: UIButton) {
if Switch1.on == true {
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "dotOn")
} else {
NSUserDefaults.standardUserDefaults().setBool(false, forKey: "dotOn")
}
}
And it works great! But in my KeyboardViewController.swift in another target of the App I have in the viewDidAppear(animated: true) :
if NSUserDefaults.standardUserDefaults().boolForKey("dotOn") == true {
let bSelector : Selector = "dotAfterSpace:"
let doubleTapGesture = UITapGestureRecognizer(target: self, action: bSelector)
doubleTapGesture.numberOfTapsRequired = 2
space.addGestureRecognizer(doubleTapGesture)
} else { }
And this function without the "if" works well... what should I do?
After some advice I wrote this code... but where am I wrong?
In KeyboardViewController.swift:
class KeyboardViewController: UIInputViewController {
var otherController = ViewControllerSettings()
override func viewDidAppear(animated:Bool) {
super.viewDidAppear(animated)
KeyboardViewController().otherController = ViewControllerSettings()
if otherController.dotOn {
let bSelector : Selector = "dotAfterSpace:"
let doubleTapGesture = UITapGestureRecognizer(target: self, action: bSelector)
doubleTapGesture.numberOfTapsRequired = 2
space.addGestureRecognizer(doubleTapGesture)
} else { }
let aSelector : Selector = "spacePressed:"
let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
tapGesture.numberOfTapsRequired = 1
space.addGestureRecognizer(tapGesture)
}
In ViewControllerSettings.swift:
class ViewControllerSettings: UIViewController {
var dotOn = Bool()