0

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) } 
2
  • 1
    isEditableSwitch is probably an implicitly unwrapped interface builder outlet to a UISwitch (i.e. @IBOutlet var isEditableSwitch: UISwitch!) which you never hooked up. This has been asked thousands of times, please look search and look at the other answers Commented Jul 28, 2020 at 20:25
  • Thanks. this solves my problem Commented Jul 28, 2020 at 20:51

1 Answer 1

1

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! 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it solves my problem, I don't know why I missed this connection.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.