Alright, so I was following a tutorial for Swift 2 even though I'm running Swift 4, I did not think it mattered much since everything that the tutorial said worked on for my code. However, I ran into a problem with adding to the score. The code went something like
@IBAction func RedBtnAction(_ sender: Any) {
Score ++
RedBtnLbl.text = "\(Score)"
BluBtnLbl.text = "\(Score)"
}
but I saw that, that was not used still in Xcode 9 or Swift 4. I searched it up and actually found an answer here! It said change the (Score ++) to (Score += 1) so I did that but it then gave me NSUnknownKeyException. My whole code goes like this right now and its still giving me the error so could somebody help?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var TopBtn: UIButton!
@IBOutlet weak var BtmBtn: UIButton!
@IBOutlet weak var RedBtnLbl: UILabel!
@IBOutlet weak var BluBtnLbl: UILabel!
var Score = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Score = 0
RedBtnLbl.text = "\(Score)"
BluBtnLbl.text = "\(Score)"
RedBtnLbl.transform = CGAffineTransform(rotationAngle: 3.14)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func RedBtnAction(_ sender: Any) {
Score += 1
RedBtnLbl.text = "\(Score)"
BluBtnLbl.text = "\(Score)"
}
@IBAction func BluBtnAct(_ sender: Any) {
Score -= 1
RedBtnLbl.text = "\(Score)"
BluBtnLbl.text = "\(Score)"
}
}
Thanks Again! Link to tutorial: https://www.youtube.com/watch?v=mNFXvceJ0wc&t=412s