Alex7 Alex7 - 3 months ago 36
Swift Question

JSQMessagesViewController + Firebase (3.4.0)

I recently updated my project from Firebase (2.5.1) to Firebase (3.4.0) by installing the following in my Podfile:

pod 'Firebase/Database'

pod 'Firebase/Core'

pod 'Firebase/Auth'

With that being said, I updated my project according to the FirebaseDatabase documentation since my app mainly uses real-time database and authentication.

At the moment I'm experiencing some very tricky errors and I have not been able to work through the following:

private func observeMessages() {
let messagesQuery = messageRef.queryLimitedToLast(25)
messagesQuery.observeEventType(.ChildAdded, withBlock: { snapshot in

let id = snapshot.value!["senderId"] as! String
let text = snapshot.value!["text"] as! String

self.addMessage(id, text: text)

self.finishReceivingMessage()
})
}


I've tried fixing it to the best of my ability to no avail
and my app keeps crashing due to this

I didn't have this problem when I had Firebase (2.5.1) in my podfile so I'm certain its attributed to the new update.

If anyone could kindly advise me on how to navigate through this error, please feel free to comment and offer any kind of suggestions in relation to this issue. Thank you.

8/25/16

Solution:

private func observeMessages() {
let messagesQuery = messageRef.queryLimitedToLast(25)
messagesQuery.observeEventType(.ChildAdded) { (snapshot: FIRDataSnapshot!) in
if let id = snapshot.value!["senderId"] as? String, text = snapshot.value!["text"] as? String {
self.addMessage(id, text: text)
self.finishReceivingMessage()
}
}
}

Answer

Solution:

private func observeMessages() {
let messagesQuery = messageRef.queryLimitedToLast(25)
messagesQuery.observeEventType(.ChildAdded) { (snapshot: FIRDataSnapshot!) in
    if let id = snapshot.value!["senderId"] as? String, text = snapshot.value!["text"] as? String {
    self.addMessage(id, text: text)
    self.finishReceivingMessage()
      }
    }
  }
Comments