[solved] Tutorial 1: lroundf(slider.value) return only 0 or 1

5th. Xcode 8.2. Swift 3.0.2

class ViewController: UIViewController {

var currentValue: Int = 0
var targetValue: Int = 0

@IBOutlet weak var slider: UISlider!

@IBAction func sliderMoved(_ slider: UISlider) {
    currentValue = lroundf(slider.value)
    print(currentValue)
}

func startNewRound() {
    targetValue = 1 + Int(arc4random_uniform(100))
    currentValue = 50
    print(currentValue)
    slider.value = Float(currentValue)
    print(slider.value)
}

viewDidLoad() invokes startNewRound(). Output: 50 and 1.0 → slider button is always on the right because of 1.0. If I move the slider button under 50 output is always 0 and upper 50 then 1. My workaround is: currentValue = Int(slider.value * 100)
I would like to use swift function and not workaround.

Looks like you did not change the minimum and maximum value of the slider in the storyboard. By default the left side is 0 and the right side is 1. The tutorial says to change the maximum from 1 to 100.

1 Like

Thank. Problem solves.