0

I have a little problem but I can't figured out ...

I code a sort a Shutdown countdown and I need to re-use the variable name "x" in the following code :

@IBAction func valueChange(sender: NSSlider) {
    let x = sender.intValue
    valueofSlider.stringValue = "\(x)"

}

IBOutlet weak var countDown: NSTextField!


var starter = false;

@IBAction func startCountDown(sender: NSButton) {
        starter = true
    }



var trigger = 600 //here I put the value myself but i would like
var trigger = (x * 60) //to get the slider value in seconds
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Pablo Clsn
  • 13
  • 1
  • 6

1 Answers1

0

First create an Outlet for your slider and then a variable to hold its value. Assign the variable inside valueChanged and now you can use it wherever you want:

@IBOutlet var slider: UISlider!
var sliderValue: Float = 0

@IBAction func valueChanged(sender: AnyObject) {
    sliderValue = slider.value
    print(sliderValue)
}
squarehippo10
  • 1,855
  • 1
  • 15
  • 45