Laynay
Laynay

Reputation: 21

Swift 3 xcode 8 firebase database error when update data

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.

Upvotes: 2

Views: 1508

Answers (3)

PaulpolS
PaulpolS

Reputation: 31

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)

Upvotes: 3

Carlos Norena
Carlos Norena

Reputation: 115

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

Upvotes: 1

makthrow
makthrow

Reputation: 139

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

Upvotes: 0

Related Questions