2

Morning everyone, I'm using Firebase and upgrade to the new version of Xcode I encountered a problem sending more data to the Firebase database. Here is the error:

Terminating app two to uncaught exception 'InvalidFirebaseData', reason: '(setValue :) Can not store object of type _SwiftValue at SenderId. Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray. '

I understand what is the problem and I also searched on the internet, the data I'm uploading are strings, after upgrading to Xcode gives me this error, does anyone have the same problem?

Should wait for a few days, I have also tried to update Firebase but there is no update for the library.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Laynay
  • 21
  • 3
  • 1
    Give your code Where you face that error – Dravidian Sep 14 '16 at 12:11
  • Which Swift version are you using? Maybe you have to set the legacy value for Swift 2.3? http://stackoverflow.com/questions/39490507/how-can-i-use-swift-2-3-on-xcode8 – M_G Sep 14 '16 at 12:43
  • swift 3, that's my code: override func didPressSend(_ button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: Date!) { let newMessageRef = messageRef.child(roomId).childByAutoId() let mes = ["text": text, "senderId": senderId, "senderName": senderDisplayName, "MediaType": "text"] newMessageRef.setValue(mes) self.finishSendingMessage() } – Laynay Sep 16 '16 at 13:48
  • i'm using jsqmessageviewcontroller – Laynay Sep 16 '16 at 13:48

3 Answers3

3

It worked on JSQMessage too!!!

var messageRef = FIRDatabase.database().reference().child("messages")

let newMessage = messageRef.childByAutoId()
let messageData: Dictionary<String, Any>? = ["text": text, "senderId": senderId, "senderName": senderDisplayName, "mediaType": "TEXT"]
newMessage.setValue(messageData)
Bryan
  • 14,756
  • 10
  • 70
  • 125
PaulpolS
  • 31
  • 1
  • I resolved the problem using String as! NSString in my upload to Firebase Database, in DidPressSend Button – Laynay Oct 01 '16 at 18:43
1

i have been working on the same JSQMessage library ,, change your button code to this ,, i got it fixed ,, let me know how it goes

var messageRef = FIRDatabase.database().reference().child("messages")


override func didPressSend(_ button: UIButton!, withMessageText text:   String!, senderId: String!, senderDisplayName: String!, date: Date!) {

    let newMessage = messageRef.childByAutoId()

    let messageData: Dictionary<String, Any>? = ["text": text, "senderId": senderId, "senderName": senderDisplayName, "mediaType": "TEXT"]

     newMessage.setValue(messageData)

}

i added the Dictionary< String, Any>? on the second line of code inside my button action to fix the issue

  • I resolved the problem using String as! NSString in my upload to Firebase Database, in DidPressSend Button – Laynay Oct 01 '16 at 18:43
0

I have the same error. this is how I fixed it:

my code that had an error:

    var videoInfoDic: Dictionary<String, Any?>?

how i fixed:

    var videoInfoDic: Dictionary<String, Any>?

took away the optional part. credit to: https://stackoverflow.com/a/39486888/5792500

Community
  • 1
  • 1
makthrow
  • 129
  • 1
  • 16
  • I resolved the problem using String as! NSString in my upload to Firebase Database, in DidPressSend Button – Laynay Sep 23 '16 at 12:41