Just started on the iOS Apprentice (still on the first one, Bull’s Eye, page 65). I did everything that I was told to do, but I keep getting this message. Thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0).
I get the error at the line; (slider.value) = Float(currentValue)
Can someone please explain what I did wrong and how I can solve the error?
Here is my code.
import UIKit
class ViewController: UIViewController {
var currentValue: Int = 50
var targetValue: Int = 0
@IBOutlet weak var slider: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
startNewRound()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func startNewRound() {
targetValue = 1 + Int(arc4random_uniform(100))
currentValue = 50
(slider.value) = Float(currentValue)
}
@IBAction func showAlert() {
let message = "The value of the slider is: \(currentValue)"
+ "\nThe target value is: \(targetValue)"
let alert = UIAlertController(title: "Hello, World",
message: message, preferredStyle: .Alert)
let action = UIAlertAction(title: "OK", style: .Default, handler: nil)
alert.addAction(action)
presentViewController(alert, animated: true, completion: nil)
startNewRound()
}
@IBAction func sliderMoved(slider: UISlider) {
currentValue = lroundf(slider.value)
}
}