I've got one label startTime.text
that displays a timestamp (hh:mm:ss), and I've got another label nextDose.text
that I want to display the sum of startTime.text
and the hours the user inputs into freq.text
textfield. I've found that multiplying the number of hours by 3600 gives you the total amount of seconds to add to the timestamp to get the result I need, but I'm not getting the result I need. What am I doing wrong?
override func viewDidLoad() {
super.viewDidLoad()
//the following code inputs the current time into the startTime label
let dateFormatter = DateFormatter()
dateFormatter.timeStyle = .medium
let timeString = dateFormatter.string(from: Date() as Date)
startTime.text = String(timeString)
//the following code inputs the current time into the nextDose label
let freqHour = Int(freq.text!)
let hoursToSecs = Int(3600 * freqHour!)
nextDose.text = String(hoursToSecs)
}
When I run the simulator, my tableview is the first thing I see, and when I click on the "+" symbol to add another item, the app crashes and I get this error: fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
I haven't quite wrapped my head around Optionals, so I'm not sure how to proceed from here.