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.