0

in this issue i tried to unwrap it by adding ! next verifiedLabel in viewDidLoad to become verifiedLabel!.text but the result is still printing Fatal error: Unexpectedly found nil while unwrapping an Optional value. Thank you

override func viewDidLoad() {
    super.viewDidLoad()
    verifiedLabel.text = "" }


 self.verifiedLabel.text = user.isPhoneVerified ? "Verified" : "Not Verified" }

enter image description here

1 Answers1

2

You are force unwrapping an optional by adding a !, so if the value is null like it is in your case the program will crash.

To unwrap an optional in a safe way (for a generic case) follow this method from Hacking With Swift:

var name: String? = nil
if let unwrapped = name {
print("\(unwrapped.count) letters")
} else {
print("Missing name.")
}

In your SPECIFIC case however verifiedLabel is likely your label set on a storyboard. So you can unwrap it like var verifiedLabel:UILabel! since the value should NOT be null.

So now since its null, a) please check your outlet connections and if everything looks good b) check this thread for debugging: IBOutlet is nil, but it is connected in storyboard, Swift

Mohammad Assad Arshad
  • 1,535
  • 12
  • 14