-3

im having this problem: Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

is there any way to solve it?

this is my code:

let ref = Database.database().reference()



           ref.child("ChildA").child("Title").observeSingleEvent(of: .value, with: { DataSnapshot in

               print(DataSnapshot)     // replace this with textLabel or other item
               let m = DataSnapshot.value as? String
               self.TitleA.text = m //Error in this line
           })
Myz
  • 71
  • 1
  • 9
  • Did you check [What does “Fatal error: Unexpectedly found nil while unwrapping an Optional value” mean?](https://stackoverflow.com/q/32170456/1187415) Did you read *all of it?* Could it be that `TitleA` is not properly connected in the Storyboard? – Martin R May 14 '20 at 14:29
  • @sasquatch it works on other viewControllers tho – Myz May 14 '20 at 14:32
  • As pointed out by @MartinR, `TitleA` is probably nil – saurabh May 14 '20 at 14:33

1 Answers1

0

Replace:

self.TitleA.text = m

With this:

self.TitleA?.text = m ?? ""
Frankenstein
  • 15,732
  • 4
  • 22
  • 47