SlepperWL
SlepperWL

Reputation: 3

why I have this Fatal error Unexpectedly found nil while implicitly unwrapping an Optional value

I have this Fatal error(Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file), and the Xcode remind me it's this line has issue "let isEditable: Bool = isEditableSwitch.isOn" but you can see, it's not an optional value. Any one can help? by the way, I want use the On/Off status of a switch button to generate a bool value to show user whether the content is editable or not.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    super.prepare(for: segue, sender: sender)
    guard segue.identifier == "SaveUnwind" else { return }
    let title: String = titleTextField.text!
    let content: String = contentTextView.text ?? ""
    let createDate: Date = Date()
    let showDae: Date = dueDatePicker.date
    let image: UIImage? = contentImageView.image
    let isEditable: Bool = isEditableSwitch.isOn
    
    letter = Letter(title: title, content: content, image: image, createdDate: createDate, showDate: showDae, isEditable: isEditable)
}

Upvotes: 0

Views: 9441

Answers (1)

Frankenstein
Frankenstein

Reputation: 16341

The connection from storyboard to isEditableSwitch seems to be missing here. You have to reconnect it by control-dragging and dropping from the UISwitch in the storyboard to this line in your code:

@IBOutlet weak var isEditableSwitch: UISwitch!

Upvotes: 1

Related Questions