0

I have the following code using Facebook's Swift API:

        let displayName = user.displayName

        print(displayName)

        self.nameLabel.text = displayName

The displayname variable is printed correctly but when it reaches the last line, I get Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value. But displayName has a value?

User9123
  • 29
  • 1
  • 2
  • Change the last line to 'self.nameLabel?.text = displayName' and see if it still fails. If it does not, then nameLabel is nil. – totiDev Jul 13 '18 at 13:56

1 Answers1

0

This might be due to nameLabel being nil. Make sure the IBOutlet is connected properly. If the nameLabel can be nil, avoid the crash using this:

self.nameLabel?.text = displayName
Daniyal Raza
  • 352
  • 3
  • 13