Building the ToDo app. The app crashes when the new todo task is created.
The breakpoint stops the code and returns:
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
@IBAction func doneButton(_ sender: UIButton) {
guard let title = textView.text, !title.isEmpty else {
return
}
let todo = Todo(context: managedContext)
todo.title = title
todo.priority = Int16(segmentedControl.selectedSegmentIndex)
todo.date = Date()
do {
try managedContext.save()
dismiss(animated: true)
textView.resignFirstResponder()
} catch {
print("Error saving todo: \(error)")
}
}
@IBAction func cancelButton(_ sender: UIButton) {
dismiss(animated: true)
textView.resignFirstResponder()
}
Any ideas what could have caused the app crash? Thanks
textView
? And thesegmentedControl
? If those are IBOutlets, make sure they're hooked up properly in the storyboard. – LinusGeffarth