I am new to iOS development. I am doing this project by watching video tutorial, where they are using the earlier version of Swift, but I am using Swift.
I came across to this problem. Two optional integers are unwrapped when being used for calculation. But it is not unwrapped when the text is given to the label.
I tried to unwrap them again when the text is given to the label and it worked. Why it is behaving strange?
var leftNumber: Int!
var rightNumber: Int!
func generateProblem() {
leftNumber = generateRandomNumber()
rightNumber = generateRandomNumber()
// The problem is here
problemLabel.text = "\(leftNumber) x \(rightNumber)"
}
func generateRandomNumber() -> Int {
return Int(arc4random_uniform(UInt32(9))) + 1
}
The screenshot of simulator: