I'm trying to set up an egg timer, and display a countdown when the button is pressed. If "Soft" is pressed, the countdown begins at 300 seconds and so on.
However, this message keeps coming up "cannot convert value of type String to expected argument type String". What should I do?
and here is the code:
import UIKit
class ViewController: UIViewController {
let eggTimer = ["Soft" : 300, "Medium" : 420, " Hard" : 720]
var secondsRemaining = 60
@IBAction func hardnessPressed(_ sender: UIButton) {
let hardness = [sender.currentTitle!]
secondsRemaining = eggTimer[hardness]!
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
}
@objc func updateTimer() {
if secondsRemaining > 0 {
print(" \(secondsRemaining) second")
secondsRemaining -= 1
}
}
}