0

I am trying to implement an id/token for the fcm push notification. I stored the id/token in my firebase database. I am having an issue getting the constant value to match the snapshot value. Here is code and a picture. [![enter image description here][1]][1]

enter image description here

let database = self.ref.child("\(safetyEmail)").child("uid")
               
let otherUseruid = database.observe(.value) { snapshot in

    guard let ouid = snapshot.value as? String else {
        return
    }
    
    print("this is the ouid: \(ouid)")

}

print("this is the otherUseriD: \(otherUseruid)")

What isn't the otherUseruid the same value as the ouid?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • The screenshot says that an error occurred, `success: 0, failure: 1` – vadian May 14 '21 at 19:46
  • yes, that is a separate issue it has to do with an Invalid Registration. I am trying to get a user's uid to be the registration/fcm token. – personal problem May 14 '21 at 19:49
  • Please do not post images of code. https://idownvotedbecau.se/imageofcode – Andrew May 14 '21 at 20:02
  • 1
    Data is loaded from Firebase asynchronously. If you check the order in which the code is executed, you'll see that this `print("this is the otherUseriD` runs before `print("this is the ouid:`. This is the expected behavior, and means that any code that needs the data from the database needs to be inside the callback/closure, be called from there, or needs to be synchronized with a dispatch group. I've linked a few previous questions that cover this, and you can fine more example here: https://stackoverflow.com/search?tab=votes&q=%5bfirebase-realtime-database%5d%5bswift%5d%20asynchronous%20 – Frank van Puffelen May 14 '21 at 20:12

0 Answers0