Puneet Puneet - 1 month ago 10
Swift Question

How do you round a UISlider to an int in swift

I was wondering how to round a UISilder value to a int value. Right now it is displaying floats. I am using swift 3 at the moment.

@IBOutlet var slidermove: UISlider!

@IBAction func SliderVal(_ sender: AnyObject) {

print(slidermove)
let x = round(slidermove)
}


round() does not work it will give an error, thanks for anyone that helps

Answer

Try Int(slidermove.value) instead this will parse it to an Int.