title: retrieve chat message in firebase issue in ios swift
body: <p><a href="https://i.stack.imgur.com/rvctL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rvctL.png" alt="enter image description here"></a></p>
  
  <p>I am using firebase for chat app.when I try to send a message. than message, table got value but not update chat-message table. I refer to this link Here [<a href="https://github.com/DevSurya/ChatApp-Swift-And-Firebase]" rel="nofollow noreferrer">https://github.com/DevSurya/ChatApp-Swift-And-Firebase]</a>.</p>
  
  <p>when I run demo its working fine. Observe method is not calling in my case and collectionview is not refreshing </p>
  
  <p>This is how I write data :</p>
  
  <pre><code>private func sendMessageWithProperty(_ property: [String: AnyObject]){
          let ref = Database.database().reference().child("messages")
          let childRef = ref.childByAutoId()
          let toId = user!.id!
          let fromId = Auth.auth().currentUser!.uid
          let timeStamp = NSNumber.init(value: Date().timeIntervalSince1970)
          var values: [String : AnyObject] = ["toId":toId as AnyObject, "fromId":fromId as AnyObject, "timeStamp":timeStamp]
  
          values = values.merged(with: property)
  
          childRef.updateChildValues(values)
  
          childRef.updateChildValues(values) { (error, ref) in
              if error != nil {
                  print(error!)
                  return
              }
              self.inputTextField.text = nil
              let userMessageRef = Database.database().reference().child("user-messages").child(fromId).child(toId)
              let messageId = childRef.key
              userMessageRef.updateChildValues([messageId: 1])
  
              let recipentUserMessageRef = Database.database().reference().child("user-messages").child(toId).child(fromId)
              recipentUserMessageRef.updateChildValues([messageId: 1])
          }
      }
  </code></pre>
  
  <p>This is how I read data </p>
  
  <pre><code> func observeMessage() {
      guard let uid = Auth.auth().currentUser?.uid, let toId = user?.id else {
          return
      }
      let userMessageRef = Database.database().reference().child("user-messages").child(uid).child(toId)
      userMessageRef.observe(.childAdded, with: { (snapshot) in
          let messageId = snapshot.key
          let messagesRef = Database.database().reference().child("messages").child(messageId)
          messagesRef.observeSingleEvent(of: .value, with: { (snapshot) in
              guard let dict = snapshot.value as? [String: AnyObject] else {
                  return
              }
              let message = Message()
              message.setValuesForKeys(dict)
                  self.messages.append(message)
                  DispatchQueue.main.async {
                      self.collectionView?.reloadData()
                      let indexpath = NSIndexPath.init(item: self.messages.count-1, section: 0)
                      self.collectionView?.scrollToItem(at: indexpath as IndexPath, at: .bottom, animated: true)
                  }
          }, withCancel: nil)
      }, withCancel: nil)
  }
  </code></pre>
  
  <p>The ObserveMessage() function get automatically called when there is an update in database.but in my case its not get called. I think the problem is with user-messages table: it is not created when I send message.</p>